4

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?

Jahnvi
  • 43
  • 1
  • 2
  • 1
    Note: the function is declared in the header file but not defined in the header file. Is there a node.get_declaration function? – user253751 Feb 06 '20 at 12:01

1 Answers1

2

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

Jo Bo
  • 136
  • 7