Identifying function calls made to a library

Hi Guys,

I am trying to identify all the function calls made to a particular library. While visiting all the statements in the Clang AST, I can find the “CallExpr” but I don’t know how I can figure out if the callee belongs to a particular library.

What characteristics a callee belonging to a library will have? Is there even a way to distinguish a callee in a library from a callee defined in the same source file? Please let me know.

Thanks a lot !


The compiler itself has no idea where your calls point to. It just requires that you provide declaration for functions and classes you’re using and these are pulled in via includes.

That doesn’t mean that you can’t detect this yourself. If your library headers are located inside /mylib you could:

  • get the callee from CallExpr
  • get the location of the function or member declaration
  • and ask SourceManager what file it belongs to
  • compare paths.