相关疑难解决方法(0)

转储包括来自g ++的路径

我正在尝试编写一个小的构建脚本 - 并且想要确定包含是否包含系统.所以我希望g ++告诉我它正在使用的包含路径.

cpp -v似乎是最好的镜头,但它并没有给我C++路径.

所以我尝试过:

g++ -Xpreprocessor -v  
Run Code Online (Sandbox Code Playgroud)

哪个不能正常工作 - g ++捕获-v为它自己的详细输出.

谢谢,奥利弗

build-automation g++ path include

62
推荐指数
1
解决办法
3万
查看次数

Python clang 不搜索系统包含路径

当从 Python 使用 libclang 时,它似乎不会自动搜索系统的包含路径。

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

例如,给定 test.cpp

#include <stdio.h>

int main()
{
  puts("Hello, world!");
}
Run Code Online (Sandbox Code Playgroud)

和测试.py

from clang.cindex import Index

tu = Index.create().parse(None, ["test.cpp"])
print(list(tu.diagnostics))
Run Code Online (Sandbox Code Playgroud)

运行python test.py将打印:

[<Diagnostic severity 4, location <SourceLocation file 'test.cpp', line 1, 
 column 10>, spelling "'stdio.h' file not found">]
Run Code Online (Sandbox Code Playgroud)

当然,我可以通过以下方式找到系统包含路径

$ clang -v -E test.cpp
Run Code Online (Sandbox Code Playgroud)

并添加"-Isome/path"parse参数列表中,即

args = ["-I/Applications/[...]", "test.cpp"]
Run Code Online (Sandbox Code Playgroud)

这确实有效并且不会产生任何错误。

然而,这不是可移植的,如果我能够以编程方式让 clang 自动使用它们,那就太好了。

c++ python clang libclang

8
推荐指数
1
解决办法
2434
查看次数

用 libclang 解析;无法解析某些标记(Windows 中的 Python)

我有一些代码(从这里这里获取和改编),它使用libclang 解析Python(Widnows)中的C++ 源文件并获取其所有声明语句,如下所示:

import clang.cindex

def parse_decl(node):
    reference_node = node.get_definition()
    if node.kind.is_declaration():
        print(node.kind, node.kind.name, 
              node.location.line, ',', node.location.column, 
              reference_node.displayname)

    for ch in node.get_children():
        parse_decl(ch)

# configure path
clang.cindex.Config.set_library_file('C:/Program Files (x86)/LLVM/bin/libclang.dll')

index = clang.cindex.Index.create()
trans_unit = index.parse(r'C:\path\to\sourcefile\test.cpp', args=['-std=c++11'])

parse_decl(trans_unit.cursor)
Run Code Online (Sandbox Code Playgroud)

对于以下 C++ 源文件 ( test_ok.cpp):

/* test_ok.cpp
 */

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

int main (int argc, char *argv[]) {
  int linecount …
Run Code Online (Sandbox Code Playgroud)

python parsing clang c++11 libclang

4
推荐指数
1
解决办法
1990
查看次数

标签 统计

clang ×2

libclang ×2

python ×2

build-automation ×1

c++ ×1

c++11 ×1

g++ ×1

include ×1

parsing ×1

path ×1