使用Clang工具解析C ++标准头文件时出错

时间:2014-07-14 18:15:04

标签: c++ clang

我正在使用clang工具来解析位于/usr/lib/gcc/x86_64-linux-gnu/4.7/string中的标准头文件。但是我收到以下错误。

In file included from ~/PrototypeWork/user/header.hpp:3:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/string:41:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/char_traits.h:41:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/postypes.h:41:
/usr/include/c++/4.7/tr1/cwchar:42:14: error: no member named 'wcstof' in namespace 'std'
  using std::wcstof;
        ~~~~~^
/usr/include/c++/4.7/tr1/cwchar:45:14: error: no member named 'vfwscanf' in namespace 'std'
  using std::vfwscanf;
    ~~~~~^

问题似乎是clang正在读取字符串标题而不是c ++标题,所以它无法解析"使用"关键词。 所以我继续添加-TP命令行选项,将所有源文件视为C ++,但没有帮助。

使用-TP命令行选项

后,我收到以下警告
warning: argument unused during compilation: '-T P'

任何人都可以帮我解决这个问题吗?

Clang命令行选项:http://clang.llvm.org/docs/UsersManual.html#id5

代码

我的主要功能有:

    int main() {
    std::vector<std::string> cmdLine = boost::assign::list_of
                        ("-TP")
                        ("-I/usr/include")
                        ("-I/usr/include/c++/4.7/tr1/");
    clang::tooling::FixedCompilationDatabase db(".",cmdLine); 

// Provide clang with the header file that needs to be parsed

// Run the clang tool .
}

1 个答案:

答案 0 :(得分:2)

对不起,如果这是&#34;谢谢你,明天上尉&#34;回答,但是:被解析的代码是否可能只是#include <cwchar>?默认情况下,clanggcc更严格,因此如果您未能包含声明该功能的标头,则会发现此类错误。