Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using LibClang to list down all function calls and their corresponding definition. Following is the python script to do so:

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

Following is the cpp code I run this on:

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

Now, for the CXcursor referring to sqrt, I get the output sqrt , None

Can somebody explain why is it not able to find the definition of the function?

like image 586
Jahnvi Avatar asked Sep 03 '25 10:09

Jahnvi


1 Answers

Run your libclang parsing method (whichever you use) with the -I path/to/header/directory argument

like image 123
Jo Bo Avatar answered Sep 05 '25 00:09

Jo Bo