为什么 Libclang 无法获取头文件中定义的函数的定义?

Why is Libclang unable to get definition of a function defined in a header file?

我正在使用 LibClang 列出所有函数调用及其相应的定义。 以下是执行此操作的 python 脚本:

def traverse(node):
   if node.kind == CALL_EXPR:
       print(node.displayname, node.get_defintion()) 
   for c in node.get_children():
       traverse(c)

以下是我在运行上的cpp代码:

#include<math.h> 
int main()
{
   float n = sqrt(3.0);
}

现在,对于引用 sqrt 的 CXcursor,我得到输出 sqrt ,None

谁能解释一下为什么找不到函数的定义?

运行 您的 libclang 解析方法(无论您使用哪种方法)与 -I path/to/header/directory 参数