libclang:添加编译器系统包含路径(Windows中的Python) [英] libclang: add compiler system include path (Python in Windows)

查看:229
本文介绍了libclang:添加编译器系统包含路径(Windows中的Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循此问题 Andrew的建议,我正在尝试 liblang 添加编译器系统的包含路径(在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)

完全 像这样解析C ++源文件

/* test.cpp
*/
#include <iostream>
#include <vector>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

void readfunction(vector<double>& numbers, ifstream& myfile)
{

  double number;
  while (myfile >> number) {
  numbers.push_back(number);}

}

double meanfunction(vector<double>& numbers)
{

  double total=0;
  vector<double>::const_iterator i;
  for (i=numbers.begin(); i!=numbers.end(); ++i) {
  total +=*i; }
  return total/numbers.size();

}

现在,在没有正确设置编译器包含路径的情况下(使用Windows),我得到以下输出:

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

<Diagnostic severity 4, location <SourceLocation file 'test.cpp', line 3, column 10>, spelling "'iostream' file not found">

不幸的是,我对这种方法或如何实现此我的Python代码中的href ="https://stackoverflow.com/questions/26440911/python-clang-does-not-search-system-include-paths">解决方案.

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

我也尝试过 ccsyspath ,但是我不具备针对Windows对其进行调整的技能" '.

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

有人知道如何解决这个问题吗?

Anyone knows how to solve this issue?

推荐答案

在Windows中,要向路径添加内容,您必须执行以下操作:

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

  1. 系统属性
  2. 高级
  3. 环境变量
  4. 从表中选择路径"
  5. 第一个编辑"按钮
  6. 添加您要添加​​到路径的可执行文件的位置

希望这会有所帮助!

((如果我误解了您的问题,请告诉我,我仍然是堆栈溢出的新手.谢谢!)

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

这篇关于libclang:添加编译器系统包含路径(Windows中的Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆