我正在使用 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/