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.
In the headers of the library (dozens... or hundreds of files), some macros/symbols are defined.
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.
I can produce a list of defined symbols with gcc preprocessor options:
gcc -E -dM include/great_lib.h | sort -V >symbols.txt
This outputs in file symbols.txt a sorted list of all the defined symbols included in a user file when it includes this header.
However, it only gives the symbol, not the file where it was defined.
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 gcc preprocessor options, I don't see a way to do that using gcc.
For example, instead of only giving me:
#define M_PI 3.14159265358979323846
it would produce
#define M_PI 3.14159265358979323846; /usr/include/math.h
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 ?
Related questions: