In a previous post about emacs etags, I received a tip from Alex Ott suggesting gtags for C/C++.
On MacOS, you can get gtags through mac ports, installing the “
To build the symbols table, it’s simple as doing:
at the root of the project.
Usage on emacs
First, you need to add a gtags-mode on emacs and tell it where to find the gtags script if gtags.el file is not installed in the default location (mac ports install it on
/opt/local/share/gtags by default). On the preferences files, I added these lines:
(setq load-path (cons "/opt/local/share/gtags/" load-path)) (autoload 'gtags-mode "gtags" "" t)
Some useful commands:
gtags-find-tag [tag name]— this command finds the definition of tag name.
gtags-find-rtag [tag name]— this command finds the usage of the tag name
gtags-find-tag-from-here— this command is a smart version of the above. It will look up the name that is pointed by your cursor. If your cursor is on a definition, it will look for usage. On the other hand, if your cursor is on a usage, it will look for the definition.
One may wish to bind this last command to some key.