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

标签 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 将字符串 header 读取为 C header 而不是 C++ header ,因此它无法解析“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 .
}

最佳答案

很抱歉,如果这是一个“谢谢你,Captain Obvious”的回答,但是:是否有可能正在解析的代码只是未能 #include <cwchar>clang默认情况下比 gcc 更严格,所以如果您未能包含声明该函数的 header ,您将看到这样的错误。

关于c++ - 使用 Clang 工具解析 C++ 标准头文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24743093/

相关文章:

c++ - 在 C++ 中解析 C++ 字符串

c++ - CLang:std::thread 中的运行函数导致结构创建时出现 BAD_ACCESS

C++11:GCC 4.8 静态 thread_local std::unique_ptr 未定义引用

c++ - C++中继承的循环依赖

c++ - 用 Metrowerks 编译器解决 boost.thread 编译错误

objective-c - 具有可修改 AST 的 Objective C 解析器(如 C# 的 NRefactory)

c - 使用 gcc 而不是使用 clang 在 for 循环错误中分配结构

c++ - clang 损坏的名称随时间变化

c++ - “输入”未命名类型错误。不知道为什么吗?

c++ - 使用 mingw 和 g++ 编译器