【问题标题】:libclang: add compiler system include path (Python in Windows)libclang:添加编译器系统包含路径(Windows 中的 Python)
【发布时间】:2016-09-03 22:32:17
【问题描述】:

按照 questionAndrew's 的建议,我正在尝试 liblang 添加编译器系统包含路径(在 Windows 中)以便我的 Python 代码

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),我会得到以下输出:

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">

不幸的是,我无法理解这个approach 或如何在我的Python 代码中实现这个solution(Python 和Clang 中的新功能)。

我也尝试过ccsyspath,但我没有“为 Windows 调整它”的技能。

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

【问题讨论】:

    标签: python c++ clang libclang


    【解决方案1】:

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

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

    希望这会有所帮助!


    (如果我误解了你的问题,请告诉我,我还是堆栈溢出的新手。谢谢!)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-07
      • 2014-12-13
      • 1970-01-01
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      • 2012-06-06
      • 2011-05-06
      相关资源
      最近更新 更多