Vim Tips Wiki

Generate ctags file for a C/C++ source file with all of their dependencies (standard headers, etc)

Revision as of 11:09, March 26, 2012 by Xuhdev (Talk | contribs)

1,619pages on
this wiki

When you want to generate a ctags file for your standard headers, you may have know the following command:

   ctags –R --c++-kinds=+p --fields=+iaS --extra=+q /usr/include 

Yes, this could really work, but sometimes you may got a HUGE tags file, with some extra symbols that has nothing to do with your project. This tip will give you a solution: generate a tags file including symbols of your C/C++ files and their including headers.

The following shell script would do this for you:

   gcc -M $* | sed -e 's/[\\ ]/\n/g' | \
           sed -e '/^$/d' -e '/\.o:[ \t]*$/d' | ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q

Assuming you have saved the code as, simple execute

   /path/to/ file1.cpp file2.c file3.cpp

then a tags file containing the symbols of the source files and headers included will be generated.

There is also a vim plugin called ProjectTag could do this, and could also work on Windows, but it requires you have your vim built with python enabled.


The shell script ProjectTag


Around Wikia's network

Random Wiki