How to find all files that constitute a translation unit in C++?
<p>I'm using a header only library and would like to include only the part of the library that I'm actually using. </p>

<p>If I include one of the library's headers how can I find all the other headers that are included by the library? Or phrased more generally: how can I find all files that make up a C++ translation unit? (I'm using g++ on Linux.)</p>

<h1>Edit: Possible approaches with gcc (answers summary)</h1>

<ul>
<li><p>gcc -H produces output of the form:</p>

<pre><code>... /usr/include/c++/4.6/cmath
.... /usr/include/math.h
..... /usr/include/x86_64-linux-gnu/bits/huge_val.h
..... /usr/include/x86_64-linux-gnu/bits/huge_valf.h
</code></pre>

<p>You have to filter out the system headers manually, though.</p></li>
<li><p>gcc -E gives you the raw preprocessor output:</p>

<pre><code># 390 "/usr/include/features.h" 2 3 4
# 38 "/usr/include/assert.h" 2 3 4
# 68 "/usr/include/assert.h" 3 4
extern "C" {    
extern void __assert_fail (__const char *__assertion, __const char *__file,
      unsigned int __line, __const char *__function)
      throw () __attribute__ ((__noreturn__));
</code></pre>

<p>You have to parse the linemarkers manually. See: <a href="http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html" rel="nofollow">http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html</a></p></li>
<li><p>gcc -M produces a Make file for the given source file. The output looks as follows:</p>

<pre><code>object.o: mylibrary/object.h /usr/include/c++/4.6/map \
 /usr/include/c++/4.6/bits/stl_tree.h \
 /usr/include/c++/4.6/bits/stl_algobase.h \
 /usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++config.h \
</code></pre></li>
</ul>
