Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用libclang解析源文件-链接include文件时出现问题_C++_Cmake_Clang_Clang++_Libclang - Fatal编程技术网

C++ 使用libclang解析源文件-链接include文件时出现问题

C++ 使用libclang解析源文件-链接include文件时出现问题,c++,cmake,clang,clang++,libclang,C++,Cmake,Clang,Clang++,Libclang,我已经编写了一个使用libclang库解析C/C++文件的脚本 我试图分析的文件:。程序打印文件中的每个函数/变量等。样本输出: ... CURSORKIND: 6; __user at line: 469 CURSORKIND: 43; struct proplistname_args at line: 469 CURSORKIND: 6; nbytes at line: 470 ... 因此,我运行脚本/script osf_sys.c,解析大部分工作正常。但是,我注意到,osf_sys.

我已经编写了一个使用
libclang
库解析C/C++文件的脚本

我试图分析的文件:。程序打印文件中的每个函数/变量等。样本输出:

...
CURSORKIND: 6; __user at line: 469
CURSORKIND: 43; struct proplistname_args at line: 469
CURSORKIND: 6; nbytes at line: 470
...
因此,我运行脚本
/script osf_sys.c
,解析大部分工作正常。但是,我注意到,
osf_sys.c
的某些部分没有被打印出来(缺少变量等等),我怀疑这与头文件(位于单独的目录中)有关。我添加了一个代码片段,以帮助调试/打印下面显示的错误消息

尝试1 使用
CMake
构建脚本后,我继续运行它。这是打印的错误:

/Linux_Kernel/linux/arch/alpha/kernel/osf_sys.c:13:10:
fatal error: 'linux/errno.h' file not found
似乎它在定位这个
osf_sys.c
的头文件时遇到了一些问题。因此,我将其添加到
CMakeLists.txt
(这可能是错误的,因为问题似乎不在于我的程序的编译,而在于libclang如何定位东西):

请注意,的完整路径是
/Linux\u Kernel/Linux/include/Linux/errno.h

尝试2 我决定将整个
include/
文件夹拖到
osf_sys.c
所在的目录中

现在,运行它会给我一个新的错误打印输出:

/Linux_Kernel/linux/arch/alpha/kernel/osf_sys.c:13:10: error:
'linux/errno.h' file not found with <angled> include; use "quotes" instead
好了,现在它好像在读什么。果然,所讨论的行是来自
osf_sys.c
文件的
#include
。 第二条错误消息可能是因为我没有将
asm/
文件夹拖到与
osf_sys.c
相同的工作目录中

尝试3 因此,根据要求,我手动编辑了
osf_sys.c
以将
#include
更改为
#include“linux.errno.h”

这一次,我将看到以下错误消息:

/Linux_Kernel/linux/arch/alpha/kernel/linux/errno.h:4:10: 
fatal error: 'asm/errno.h' file not found
尝试4 将
-I/Linux\u Kernel/Linux/include
作为参数传递到脚本中。脚本将以下参数用于
CXTranslationUnit

CXTranslationUnit translationUnit = clang_parseTranslationUnit(index, nullptr, argv, argc, 0, 0, CXTranslationUnit_KeepGoing);
这会产生其他类型的错误消息:

warning: 'linker' input unused [-Wunused-command-line-argument]
/Linux_Kernel/linux/arch/alpha/kernel/linux/errno.h:4:10: error: 'asm/errno.h' file not found
/Linux_Kernel/linux/include/linux/types.h:4:10: error: 'asm/types.h' file not found
...
还有什么事要做? 我不打算编辑所有的
#include
语句(在linux内核的每个文件中)以使用双引号,并将
include/
文件夹拖动到带有
.c
文件的每个目录中

如果您能就如何使
libclang
搜索我指定的
include/
文件目录提供一些建议,我将不胜感激


关于如何解决此问题的任何建议/备选方案?

要正确解析源文件,必须将用于编译内核的所有编译标志传递给
clang_parseTranslationUnit
(通过argv)。获取所有这些数据的最简单方法是构造。您可以尝试使用或寻找其他工具。
另外,看看类似的问题:

您可以重试尝试#3,但也可以添加包含
asm/errno.h的include目录
您曾经解决过这个问题吗?我似乎和你在同一条船上。
CXTranslationUnit translationUnit = clang_parseTranslationUnit(index, nullptr, argv, argc, 0, 0, CXTranslationUnit_KeepGoing);
warning: 'linker' input unused [-Wunused-command-line-argument]
/Linux_Kernel/linux/arch/alpha/kernel/linux/errno.h:4:10: error: 'asm/errno.h' file not found
/Linux_Kernel/linux/include/linux/types.h:4:10: error: 'asm/types.h' file not found
...