libclang:添加编译器系统包含路径(Windows中的Python)
libclang: add compiler system include path (Python in Windows)
根据这个问题和Andrew的建议,我正在尝试让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:pathtosourcefiletest.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">
不幸的是,我无法理解这种方法(Python和Clang中的新方法),也无法理解如何在我的Python代码中实现这种解决方案。
我也尝试过ccsyspath,但我不具备"针对窗口进行调整"的技能。
有人知道如何解决这个问题吗?
在Windows中,要向路径添加内容,必须执行以下操作:
- 系统属性
- 高级
- 环境变量
- 从表中选择"路径"
- 第一个"编辑"按钮
- 添加到要添加到路径的可执行文件的位置
希望这能有所帮助!
(如果我误解了你的问题,请告诉我,我还是堆栈溢出的新手。谢谢!)
相关文章:
- 分段 Linux Ubuntu 中的 g++ 错误,但在 Windows 中的 g++/MingW 中,在 C++ 中打
- 绕过 Windows 中的 __declspec(dllimport) 到 Linux 项目的转换
- 以原子方式将彩色文本写入 Windows 中的控制台
- 使用 pipe() 和 fdopen() 将数据从 Python 脚本传递到 Windows 中的C++应用程序
- 无法在windows中的virtualenv中安装psycopg2
- 从 Windows 中的其他应用程序 GUI 中提取数据
- 为什么我不能在 Windows 中的 rabbitmq 中创建队列?
- 跨平台 c++ 与 Linux 和 Windows 中的 c# 集成
- 我们如何劫持DLL以锁定Windows中的所有目录以进行验证
- QT库链接Windows中的错误
- Windows中的主音量控制,在启动时运行
- 尽管它在Linux中起作用,但无法从Windows中的Pclvisualizer中删除点云
- Windows中的CodeBlock中的设置OpenFramework
- 代码:: blocks printf double windows中的固定精度
- 在C 中将多个客户端连接到Windows中的单个服务器中的多线程
- 如何从Windows中的可执行文件中推断出文件/目录路径
- 如何将共享库 *DLL与Windows中的cmake链接
- 可以在不在Windows中的ROS的情况下安装KDL_PARSER
- 程序在Windows中的DLL边界上使用嵌入式Python/C 代码崩溃
- 如何从Windows中的进程中读取Unicode字符串