Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Here's a problem I've had recently that just HAS to be a common pain to others here.

I'm working with someone else's legacy C code and need to find where a function or macro was defined. The code #includes a bunch of different standard system libraries in addition to those from the specific project.

Is there a tool or technique to quickly find where a specific function, macro, (or other global for that matter) was defined?

I tried:

grep -R 'function' /usr/lib

and other similar *nix/bash-fu with only limited success and lots of annoying chaff to cull. One of you sage coders out there must have a good solution to this seemingly common scenario.

I was very surprised to not find another question on this particular pain here or in my searches of the interwebs. (I'm sure there will be angry comments if I missed one... ;-))

Thanks in advance for any tips!

like image 389
JJC Avatar asked Mar 27 '12 10:03

JJC


People also ask

How do you get all headers in C++?

You make the declarations in a header file, then use the #include directive in every . cpp file or other header file that requires that declaration. The #include directive inserts a copy of the header file directly into the . cpp file prior to compilation.

Which header files in C++ includes all header?

<bits/stdc++. h> in C++ It is basically a header file that includes every standard library.

How do I view header files?

To check if an header file has been included or not in a C or C++ code, we need to check if the macro defined in the header file is being defined in the client code. Standard header files like math. h have their own unique macro (like _MATH_H ) which we need to check. Consider this example of checking if math.

Which special character is used in header file?

The Hash symbol directs the compiler to load the header file in the program.


1 Answers

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.

like image 189
hroptatyr Avatar answered Sep 17 '22 13:09

hroptatyr