相关疑难解决方法(0)

转储包括来自g ++的路径

我正在尝试编写一个小的构建脚本 - 并且想要确定包含是否包含系统.所以我希望g ++告诉我它正在使用的包含路径.

cpp -v似乎是最好的镜头,但它并没有给我C++路径.

所以我尝试过:

g++ -Xpreprocessor -v  
Run Code Online (Sandbox Code Playgroud)

哪个不能正常工作 - g ++捕获-v为它自己的详细输出.

谢谢,奥利弗

build-automation g++ path include

62
推荐指数
1
解决办法
3万
查看次数

为什么Clang不带标准库头?

我从这个网站下载了Clang 3.6.2,并尝试使用Windows下的Code :: Blocks进行设置.不幸的是,由于它不知道在哪里,它无法编译一个简单的"hello world"程序iostream.

查看安装文件夹,它似乎没有包含标准库.为什么?我怎么得到它?

c++ clang standard-library llvm-clang

15
推荐指数
1
解决办法
7476
查看次数

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

按照这个问题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:\path\to\sourcefile\test.cpp', args=['-std=c++11'])

parse_decl(trans_unit.cursor)
Run Code Online (Sandbox Code Playgroud)

完全 解析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 …
Run Code Online (Sandbox Code Playgroud)

c++ python clang libclang

6
推荐指数
1
解决办法
1114
查看次数

在libclang(Python)中查找特定函数声明的所有引用

我试图通过Python中的libclang解析C++源文件时找到(行和列位置)特定函数声明的所有引用.

例如:

#include <iostream>
using namespace std;

int addition (int a, int b)
{
  int r;
  r=a+b;
  return r;
}

int main ()
{
  int z, q;
  z = addition (5,3);
  q = addition (5,5);
  cout << "The first result is " << z;
  cout << "The second result is " << q;
}
Run Code Online (Sandbox Code Playgroud)

所以,对于上面的源文件,我想要addition第5行的函数声明,我希望find_all_function_decl_references(见下文)返回第addition15行和第16行的引用.

我试过这个(改编自这里)

import clang.cindex
import ccsyspath

index = clang.cindex.Index.create()
translation_unit = index.parse(filename, args=args)

for node in …
Run Code Online (Sandbox Code Playgroud)

c++ python clang libclang

6
推荐指数
1
解决办法
2588
查看次数

在Python中使用libclang在C ++中进行解析

经过一些研究和几个问题,我最终探索了libclang库,以便用Python解析C ++源文件。

给定C ++源代码

int fac(int n) {
    return (n>1) ? n?fac(n?1) : 1;
}

for (int i = 0; i < linecount; i++) {
   sum += array[i];
}

double mean = sum/linecount;
Run Code Online (Sandbox Code Playgroud)

我试图将标记识别 fac为函数名称,n变量名称,i变量名称,mean变量名称以及每个位置。我有兴趣最终将它们标记化

我已经阅读了一些非常有用的文章(eli的Gaetan的),以及一些堆栈溢出问题3511319713236500

但是,鉴于我是Python的新手,并且努力理解libclang的基础知识,因此,我非常感谢一些示例代码块,这些代码实现了以上内容,供我学习和理解。

c++ python parsing libclang

2
推荐指数
1
解决办法
4396
查看次数