I am trying to "arm" compile a C file,it includes lot of header files recursively..i am trying to find the list of these header files..is there a easier way to find the list of all the header files it includes?
-
Yea, look in the .C file. Or alternatively, you can peek at the master header by using the -E compiler option. – Shark Apr 12 '13 at 16:10
-
Here's a hint for GCC: http://stackoverflow.com/questions/42308/tool-to-track-include-dependencies – πάντα ῥεῖ Apr 12 '13 at 16:13
-
1for Visual Studio http://msdn.microsoft.com/en-us/library/hdkef6tk%28v=vs.90%29.aspx – Apr 12 '13 at 16:23
3 Answers
You can use the GCC C preprocessor with it's option to dump a list of headers recursively included:
cpp -M
That will show you all headers included.
You will probably need to give it the roots of all include directories used in your regular build. Run it iteratively, adding more include paths until the errors stop.
The full form of this command in this usage is:
cpp -M [-I include_directory *] path_to_c_file.c
-
-
Ah, thx! I've been familiar with `gcc -M` or `g++ -M` the `cpp` command and that particular option are new to me. Does it track down the recursively included files as well? Forget about this, I got it it's the standalone preprocessor ... – πάντα ῥεῖ Apr 12 '13 at 16:18
-
3If you don't want to see system headers, replace the `-M` option with `-MM`. – ahcox Mar 05 '14 at 15:06
-
As per http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-Options -H and -M option are useful for this purpose.
Another option is to use http://www.doxygen.nl/ and generate documentation of your project, after that you can check it to see file dependencies :), it is preferred because it supports many languages: C, C++, Objective-C, C#, PHP, Java, Python, IDL (Corba and Microsoft flavors), FORTRAN, VHDL, Tcl.

- 8,285
- 3
- 19
- 32
Most compilers have switch to make them just preprocess the file. What means among other that they expand all #include
's into an actual code. And usually they do include a comment (proper C comment) on the line of original include. So you can then search the resulting preprocessed code for all such comments to collect all included headers.

- 188,800
- 56
- 490
- 992