title: Producing a list of all the preprocessor symbols defined in headers
body: <p>Say I use some C or C++ library, made out of headers and some source files, that are compiled into a static or shared library I can link with.</p>
  
  <p>In the headers of the library (dozens... or hundreds of files), some macros/symbols are defined.</p>
  
  <p>Now I want to use this library in a project, that also defines some macros and symbols. Of course, I want to avoid name collisions,
  as this has been reported sometimes, particularly with windows.h. But more generally I want to keep control of what is really exported out of that header.</p>
  
  <p>I can produce a list of defined symbols with gcc preprocessor options:</p>
  
  <pre><code>gcc -E -dM include/great_lib.h | sort -V &gt;symbols.txt
  </code></pre>
  
  <p>This outputs in file symbols.txt a sorted list of all the defined symbols included in a user file when it includes this header.</p>
  
  <p>However, it only gives the symbol, <strong>not the file where it was defined</strong>.</p>
  
  <p>I have the feeling that this could be a useful information. For example, to check if some system macro is being redefined in "great_lib.h" or its ascendants.
  Unfortunalty, after checking <a href="http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Preprocessor-Options.html" rel="nofollow noreferrer">gcc preprocessor options</a>, I don't see a way to do that using gcc.</p>
  
  <p>For example, instead of only giving me:</p>
  
  <pre><code>#define M_PI 3.14159265358979323846
  </code></pre>
  
  <p>it would produce</p>
  
  <pre><code>#define M_PI 3.14159265358979323846; /usr/include/math.h
  </code></pre>
  
  <p>Maybe something with the -dN option ? But its output is confusing for me, it requires further text processing, and I don't understand how the information is layered.
  Or a simpler way ?</p>
  
  <p>Related questions:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/10904873/">Anyway to see list of preprocessor defined macros?</a></li>
  <li><a href="https://stackoverflow.com/questions/5603870/">How can I get a list of all preprocessor symbols used (or defined) within a file?</a></li>
  </ul>