I understand that we can use nm to list the symbols in a file. But what I am looking for is to list all the headers that are included in a C++ executable.
Asked
Active
Viewed 604 times
-1
-
possible duplicate of [/show include equivalent option in g++](http://stackoverflow.com/questions/4479049/show-include-equivalent-option-in-g) (edit: Assuming you have the source to the executable, that is!) – benjymous Oct 28 '13 at 10:19
-
2@benjymous: This question is about already-compiled executables, not the compilation process. – Williham Totland Oct 28 '13 at 10:21
-
If you want to list headers from source files, look at http://stackoverflow.com/questions/15976080/list-of-all-header-files-included-by-a-c-file – otherwise you're doomed, see Williham Totland's answer. – Palec Oct 28 '13 at 10:22
-
in an executable there is nothing such as "header"..do you mean the source files? – Koushik Shetty Oct 28 '13 at 10:23
-
2As explained in Williham Totland's answer, what you are asking for is not possible. Please explain why you want to do this, i.e. what problem you are trying to solve. Maybe then we can help. – sleske Oct 28 '13 at 10:24
1 Answers
10
There is a way, and you don't need a tool for it; it's a static list:
- None. Ever.
During the compilation phase of making an executable or library, headers are included, not as symbols or dependencies, but textually. Their text is literally copied into the stream of code that is to be compiled, and their names are gone from the scrolls for all time.
Once this is done, the header files are never referenced again.
Edit: Guessing wildly here, but I'm thinking you probably want to know that libraries an executable uses; for which you can use the handy-dandy ldd
.
(As a point of interest, ldd
won't give you statically linked libraries, so you might be out of luck anyway.)

Williham Totland
- 28,471
- 6
- 52
- 68
-
I think sometimes it may be possible to get list of headers from DWARF data embedded in *debug* builds. – el.pescado - нет войне Oct 29 '13 at 07:24
-
@el.pescado: Whether or not that can be considered part of the executable is an open question; and besides; it's not something you can trust to be present. – Williham Totland Oct 29 '13 at 08:11