1

Suppose I have two files main.c and func.c func.c is called from main.c's main function. Normally, I would generate main.o and func.o and linker would find definition of func and tie it up to it's call in main .c

Now, I want to do same thing through libclang APIs. This is for a Doxygen type code browsing utility I am making. I am able to parse the two files. From here, I don't know how to proceed. Should I generate *.o files and make clang link them?

Thanks, I hope I am clear in asking the question

user763410
  • 502
  • 6
  • 22
  • Note that doxygen (as of version 1.8.4) can optionally also use libclang to do the source browsing. So you may want to try that first or have a look at src/clangparser.cpp to see how doxygen does it. – doxygen Sep 05 '13 at 15:10

1 Answers1

3

No, there is no need for actually compiling your code to object files.

The link between symbols in both translation units can be established using USR (Unified Symbol Resolution). When you find an interesting place in the AST of a translation unit (represented by a CXCursor in libclang), call clang_getCursorUSR() to get the associated USR.

If two CXCursor have the same USR, even in two different translation units, they are associated to the same symbol.

François Févotte
  • 19,520
  • 4
  • 51
  • 74
  • Thanks very much. Although I don't fully understand what you said, I get the drift. I will look at USR and CXCursor and work them. – user763410 Aug 05 '13 at 18:40
  • No problem. Please feel free to ask other questions as you encounter new problems, or to refine this one if you have a more specific issue. – François Févotte Aug 05 '13 at 18:43