Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python clang不包含搜索系统路径_Python_C++_Clang_Libclang - Fatal编程技术网

Python clang不包含搜索系统路径

Python clang不包含搜索系统路径,python,c++,clang,libclang,Python,C++,Clang,Libclang,当使用Python中的libclang时,它似乎不会自动搜索系统的include路径 有可靠的方法获得这些路径吗?我不喜欢硬编码路径,因为我正在编写将在各种UNIX系统上运行的代码 例如,给定test.cpp #include <stdio.h> int main() { puts("Hello, world!"); } 运行python test.py将打印: [<Diagnostic severity 4, location <SourceLocation f

当使用Python中的libclang时,它似乎不会自动搜索系统的include路径

有可靠的方法获得这些路径吗?我不喜欢硬编码路径,因为我正在编写将在各种UNIX系统上运行的代码

例如,给定test.cpp

#include <stdio.h>

int main()
{
  puts("Hello, world!");
}
运行
python test.py
将打印:

[<Diagnostic severity 4, location <SourceLocation file 'test.cpp', line 1, 
 column 10>, spelling "'stdio.h' file not found">]
并将
“-Isome/path”
添加到
parse
参数列表中,即

args = ["-I/Applications/[...]", "test.cpp"]
这实际上是可行的,不会产生错误

但是,这是不可移植的,如果我可以通过编程让clang自动使用它们,那将是非常好的。

这个问题已经提出了一段时间,所以我将尝试自己回答它

看起来,即使是叮当声本身也大多使用硬编码的路径

它枚举候选路径并添加适合当前上下文的路径。这可以从中看出。例如:

对于Linux,此代码具有以下注意事项:

llvm_unreachable("Include management is handled in the driver.");
clang/lib/Driver/
下,我们可以在
toolschains.cpp
crosswindowstoolschain.cpp
mingwtoolschain.cpp
等文件中找到更多这些路径


我所希望的是,
InitHeaderSearch.cpp
中的代码将通过libclang暴露给Python。

回答说只有libclang没有更好的方法(似乎libtooling更有能力);一个解决办法是添加一个调用C++ > CLAN-EX-C++/DEV/NULL——V并在Python脚本中过滤结果。考虑使用<代码> -ISSuth<代码>,而不是<代码> -i代码>通知系统包含路径的LILCLAN。
args = ["-I/Applications/[...]", "test.cpp"]
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
                           "i686-apple-darwin10", "", "x86_64", triple);
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
                           "i686-apple-darwin8", "", "", triple);

// ...
llvm_unreachable("Include management is handled in the driver.");