title: Can I get a report of ALL the libraries linked when building my C++ executable (gcc)? (including statically linked)
body: <p>I have a C++ application that I inherited, which consists of:</p>
  
  <ul>
  <li>My main app</li>
  <li>Several app-specific libraries (libapp1, libapp2, etc...)</li>
  <li>Several "third party" libraries (most "third partis are just other teams in the company") linked from both the main app, from the app-specific libappX libraries, and from other 3rd part libraries - e.g. libext1, libext2, etc...</li>
  </ul>
  
  <p>In other words, my code looks like this:</p>
  
  <pre><code>// main.C
  #include &lt;app1/a1l1.H&gt;
  #include &lt;app2/a2l1.H&gt;
  #include &lt;ext1/e1l1.H&gt;
  
  // app1/a1l1.H
  #include &lt;app1/a1l2.H&gt;
  #include &lt;ext2/e2l1.H&gt;
  
  // app2/a2l1.H
  #include &lt;ext2/e2l2.H&gt;
  
  // ext1/e1l1.H
  #include &lt;ext3/e3l1.H&gt;
  
  // ext3/e3l1.H
  #include &lt;ext4/e4l1.H&gt;
  </code></pre>
  
  <p><strong>QUESTIONs:</strong></p>
  
  <p>1) How can I tell which libraries have been linked into the final executable? <strong>This must include statically linked ones</strong></p>
  
  <p>In other words, I want an answer of "app1, app2, ext1, ext2, ext3, ext4"</p>
  
  <p>Ideally, the answer would be available from the executable itself (I have a debug version of it built in case it makes it more possible). If that's impossible, i'd like to know if there's a simple code analysis tool (iedeally something within gcc itself) to provide that analysis.</p>
  
  <p>Please note that the object files for external libraries are already built, so looking at the build logs to see what was linked, I'm worried that "ext4" won't show up in the log since we won't be building "ext3" library that is already pre-built. </p>
  
  <p>NOTE: running "nmake" with DEPS set to yes to rebuild all the is NOT an option. But i DO have access to the full source code for external libraries.</p>
  
  <p>2) A slightly separate and less important question, how can i tell a list of all the <strong>include files</strong> used in the entire source tree I'm building. Again, ideally frm already-built executable, which i have a debug version of.</p>
  
  <p>=================</p>
  
  <p><strong>UPDATE: Just to clarify, our libraries are linked statically, so <code>ldd</code> (List Synamic Dependencies) does not work.</strong></p>
  
  <p>Also, the answer can be either for Solaris or Linux - doesn't matter.</p>
  
  <p>I tried using <code>nm</code> but that doesn't list the libraries</p>