How can I quickly search all included header files in a project for a specific symbol?

为君一笑 提交于 2019-12-01 03:27:07

Use etags/ctags from the exuberant ctags project in conjunction with an editor (emacs, vim) that understands them, or GNU GLOBAL.

Oh, and if you happen to use automake it generates a target TAGS. So no need for complicated manual calls to {c,e}tags.

Use ctags/cscope + vim/emacs

you can google for their detail use.

if you use ctags + vim, you can :

1.go to the /usr/include directory, excute ctags -f tags1 -R . generate the tags

2.generate tags for your code in your code directory ctags -f tags2 -R.

3.run :set path+=tags1,tags2 in your vim

4.under a function or marco try CTRL+]

Here is what you can do, assuming you use gcc, if not just modify it accordingly.

gcc -E myfile.c | grep '^#' | cut -f 3 -d ' ' | sort |uniq | xargs -n 1 grep -l "MYMACROORFUNCTIONNAME"

You can use Eclipse CDT. For example here is described how to setup CDT project to navigate Linux kernel source - HowTo use the CDT to navigate Linux kernel source.

vim + ctags is the way to go. You can jump to and definition of functions, global variables, macros, etc. etc.

FYI, browsing programs with tags

Also, if you want to quickly switch between .c and .h files, please refer to this blog

you can use cscope or emacs/vim + xcscope.el to do that easily. I think it's batter than ctage and etage.

Provided the correct headers are included that directly or indirectly define what you look for, most IDEs have a jump-to-definition-functionality that works.

The tags-approaches are of course nice because they don't depend on correctly included headers.

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