Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I currently have a C++ project that spans two different source control systems. Without checking in the full complete source code from the first system into the second system I plan to check in just the supporting libraries that gets built. My issue is that I will need header files from the first source control system that I use in the second source control system so that I can compile. Is there an easy way of forcing gcc to output all the names of the header files that I use when I compile under Solaris? Is there a way to generate a hierarchy of header file dependencies so that I can see which files are including which other header files? Is it possible for the hierarchy to know about the #pragma once so the dependency tree doesn't include duplicates that aren't included multiple times?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Run gcc -M to generate the list of header files used by a given source file, or gcc -MM to omit system headers. The output is in a makefile format, since the option is intended to generate the build dependencies of that source file. There are ways to tweak the output format, see the available preprocessor options in the GCC manual. The default output looks like this:

foo.o: foo.c some_header.h ../include/other_header.h \
        ../../common/include/yet_another_header.h
share|improve this answer
add comment

This 1992 paper by some AT&T Research folks describes a tool "incl" that does this for C files, but as far as I know, "incl" never made it out to the great wide world.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.