GNU Global and GTAGS can't find class definitions

社会主义新天地 提交于 2020-01-22 12:40:06

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/14588350/gnu-global-and-gtags-cant-find-class-definitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!