Detonar
Detonar

Reputation: 1429

Checking value of preprocessor symbol(#define)

i'm trying to cross -ompile an application to another system. I created all dependencies and started compiling. This then stops with one of my dependency libraries, namely Qt3, causing compiler errors:

Error: expected class-name before "{" token

and

Error: "QMutex" does not name a type

I'm suspecting the Q_EXPORT symbol to be defined wrong because i forgot to simulate some environment settings. But because it's definition depends on symbols which depend on symbols which depend on symbols, and so on, it's hard to check.

Just outputing it in an test program isn't working either because the value of Q_EXPORT is not always convertable to string.

My question is: How do i check the value of a preprocessor symbol (while compiling/preprocessing) with GNU Compiler.

I thought there would be an option for this but i havn't found anything while searching on the web.

Upvotes: 0

Views: 438

Answers (1)

Mats Petersson
Mats Petersson

Reputation: 129314

Debugging of macro symbols can be tricky, because it happens before the actual compilation [1]. Running the build system in such a way that you print the actual compilation command is a good starting point.

Then you can grab the actual compile command, and substitute the -c with -E or something similar, to inspect the actual generated preprocessor output. Then locate the actual place in the source that you are compiling - expect the output from -E to be HUGE - a million lines of output is not unusual. Use the #file and #line preprocessor symbols to track which file you are in, and what line you're at.

[1] Not strictly true in all compilers, as to help with precisely the problem that macros are making it hard to follow what the code is actually doing, modern compilers expand macros during the proper parsing of the code. However, that's not helping in this particular case, apparently.

Upvotes: 1

Related Questions