Can ctags be made to follow #include directives?

后端 未结 1 349
感动是毒
感动是毒 2021-02-03 14:11

I am trying to create a target in my Makefile to automatically create a tags file using ctags.

I have a list of source files (.cpp files) but I don\'t have

相关标签:
1条回答
  • 2021-02-03 14:59

    nope. unfortunately/fortunately.

    There wouldn't be too many problems following your own includes. The problem starts with

    • conditional compilation
    • external (system) libraries.

    Fortunately, the problem for your own libraries is easily solved by doing something like

    ctags *.h *.cpp
    ctags -R src/
    

    You could hack something together with cpp and then ctags. It would not work conveniently. A half-interesting approach would be to patch ctags to follow the #line pragma's in cpp's output and hence relate all tags to their respective sources.

    However, that approach would not work as you'd expect for any preprocessor symbols/defines (macros have been expanded, so you wouldn't be able to find a macro by ctags).

    The usual way to resolve this, is to generate a 'standard' tags file for your external libraries, and

    :se tags+=/home/me/libs/tags.stdc++
    :se tags+=/home/me/libs/tags.libsox
    

    etc. Several libraries have tutorials on how to make a useful tags file for use with their libraries (or prebuilt tags files assuming a certain folder layout)

    0 讨论(0)
提交回复
热议问题