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

Error using Clang tool to parse a C++ standard header file

本文关键字:文件 出错 标准 c++ Clang 工具 使用      更新时间:2023-10-16

我使用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头而不是c++头,因此它无法解析"using"关键字。因此,我继续添加了-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 .
}

抱歉,如果这是一个"谢谢你,显而易见的船长"的回答,但是:是否有可能,被解析的代码只是失败的#include <cwchar> ?默认情况下,clanggcc更严格一些,因此,如果未能包含声明函数的头文件,则会看到如下错误: