libclang: add compiler system include path (Python in Windows)

℡╲_俬逩灬. 提交于 2019-12-08 19:36:09

问题


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 <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();

}

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

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?


回答1:


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

  1. System properties
  2. Advanced
  3. Environment variables
  4. Select "path" from the table
  5. First "edit" button
  6. 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!)



来源:https://stackoverflow.com/questions/37113241/libclang-add-compiler-system-include-path-python-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!