Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU Global and GTAGS can't find class definitions

I'm having trouble getting global to find class/struct definitions. I can find them with exuberant ctags and with cscope. All tag files are built from the same source file list. I configured and built global, et.al., only specifying --prefix. configure did find exhuberant and is using it. I've been trying global periodically over the years and it's always had this problem. Any ideas?

thanks, davep

like image 419
Outis Von Nemo Avatar asked Jan 29 '13 17:01

Outis Von Nemo


2 Answers

I've found out what I did wrong. Maybe this will help someone.

  1. Just because configure finds exuberant ctags does not means that it makes it the default parser. My ex ctags doesn't support --gtags and maybe that's why. The default parser in my case was native/builtin.
  2. The native parser treats .h as C only and does not look for C++ constructs. Oddly, it also does not find structs.

I found 2 fixes:

1) The best, if you have exuberant ctags, is to make it the default. The exuberant default configuration processes .h files properly. If it does not, use method 2. In .globalrc, change

default:\   
  :tc=native:

to 

default:\   
  :tc=ctags:

2) If you do not have exuberant ctags, edit .globalrc and change the langmap line for the builtin-parser from

builtin-parser:\
 :langmap=c\:.c.h,yacc\:.y,asm\:.s.S,java\:.java,cpp\:.c++.cc.hh.cpp.cxx.hxx.hpp.C.H,php\:.php.php3.phtml:

to

builtin-parser:\
 :langmap=c\:.c,yacc\:.y,asm\:.s.S,java\:.java,cpp\:.c++.cc.hh.h.cpp.cxx.hxx.hpp.C.H,php\:.php.php3.phtml:

I.e. remove the association of .h with C and associate it with C++. This may cause problems with C .h files. If so, you may need rename ALL C++ .h files to .hh, .hpp, .hxx, etc, as given in the langmap.

Based on my experience with C++, it looks like most people still use .h for their header files.

like image 151
Outis Von Nemo Avatar answered Nov 02 '22 11:11

Outis Von Nemo


Just export this variable and that should pretty much do. From the man page for gtags -

GTAGSFORCECPP If this variable is set, each file whose suffix is 'h' is treated as a C++ source file.

like image 21
Hrishikesh Avatar answered Nov 02 '22 13:11

Hrishikesh