Reputation: 7009
I have two large framework libraries, whose header files are included in my project. Either one works flawlessly, but including both causes erratic behaviour (but no error message related to the macro).
I assume that they both #define a macro of the same name. What is the most efficient way to identify the problematic macro?
Upvotes: 1
Views: 1897
Reputation: 40372
You should be able to run ctags
over your source.
ctags
can generate a tags file that, amongst other things, contains the names and locations of the macros in your C files.
You can control the types of symbols that ctags will store in your tags file through the use of the --c-kinds
option.
eg.
ctags --c-kinds=+d -f tags --recurse ./your_source_directory/
You can then search for duplicates in the resultant tags file.
Upvotes: 2
Reputation: 10820
Basically solution (2) would make a separation between libraries. An example of such conflict is ACE with wxWidgets (2.8 version) when forced using precompiled libraries that are compiled with different options (one library Unicode the other ASCII).
Upvotes: 1
Reputation: 89965
Try looking at the preprocessed output to determine what's different about it when you #include
the header files and when you don't. With gcc and with MSVC, you'd compile with -E
to print the preprocessor output to stdout. (It likely will be many thousands of lines, so you'll want to pipe it to a file.)
Upvotes: 3
Reputation: 22591
If the header files are badly written and #undef SYMBOL ... #define SYMBOL something-else
then you can't trace this. Simply #defining a macro twice should at least issue a warning. You'd have to look more closely at the 'erratic behavior'.
Upvotes: 3
Reputation: 27365
I assume that they both #define a macro of the same name.
That should generate at least a warning by the compiler (if they are in the same translation unit).
How do I identify redefined macros in C/C++?
As far as I know there is no straight-forward way.
Either one works flawlessly, but including both causes erratic behaviour
Can you please give us some details on the eratic behaviour? What actually happens? What makes you think it's the macro definitions?
Upvotes: 5
Reputation: 114481
grep for #define ?
are you sure the problem isn't something else than a macro (for example pragmas for structur packing, global memory allocators, global namespace for class names, messing with locale ...)
Upvotes: 1