python 编译器目录,libclang:添加编译器系统包含路径(Windows中的Python)

Following this question and Andrew's suggestions, I am trying to have liblang add the compiler system include paths (in Windows) in order for my Python code

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)

to completely parse C++ source files like this one

/* test.cpp

*/

#include

#include

#include

#include

#include

#include

using namespace std;

void readfunction(vector& numbers, ifstream& myfile)

{

double number;

while (myfile >> number) {

numbers.push_back(number);}

}

double meanfunction(vector& numbers)

{

double total=0;

vector::const_iterator i;

for (i=numbers.begin(); i!=numbers.end(); ++i) {

total +=*i; }

return total/numbers.size();

}

Now, without the compiler system include path set up appropriately (using Windows), I get the following output:

CursorKind.USING_DIRECTIVE USING_DIRECTIVE 8 , 17 std

CursorKind.VAR_DECL VAR_DECL 10 , 6 readfunction

Process finished with exit code 0

, spelling "'iostream' file not found">

Unfortunately, I cannot make sense (new in Python and Clang) of this approach or how to implement this solution in my Python code.

I have also tried ccsyspath, but I do not have the skills to 'adjust it for windows'.

Anyone knows how to solve this issue?

解决方案

In Windows to add something to the path you must do the following:

System properties

Advanced

Environment variables

Select "path" from the table

First "edit" button

Add in the location of the executable that you are trying to add to path

Hope this helps!

(Please tell me if I misunderstood your question, I am still new to stack overflow. Thanks!)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值