GCC dump preprocessor defines
Is there a way for gcc/g++ to dump its preprocessor defines from the command line? I mean things like __GNUC__
, __STDC__
, and so on.
Yes, use -E -dM
options instead of -c. Example (outputs them to stdout):
gcc -dM -E - < /dev/null
From the gcc manual:
Instead of the normal output, generate a list of `#define' directives for all the macros defined during the execution of the preprocessor, including predefined macros. This gives you a way of finding out what is predefined in your version of the preprocessor. Assuming you have no file foo.h, the command
touch foo.h; cpp -dM foo.h
will show all the predefined macros.
If you use -dM without the -E option, -dM is interpreted as a synonym for -fdump-rtl-mach.
I usually do it this way:
$ gcc -dM -E - < /dev/null
Note that some preprocessor defines are dependent on command line options - you can test these by adding the relevant options to the above command line. For example, to see which SSE3/SSE4 options are enabled by default:
$ gcc -dM -E - < /dev/null | grep SSE[34]
#define __SSE3__ 1
#define __SSSE3__ 1
and then compare this when -msse4
is specified:
$ gcc -dM -E -msse4 - < /dev/null | grep SSE[34]
#define __SSE3__ 1
#define __SSE4_1__ 1
#define __SSE4_2__ 1
#define __SSSE3__ 1
Similarly you can see which options differ between two different sets of command line options, eg compare preprocessor defines for optimisation levels -O0
(none) and -O3
(full):
$ gcc -dM -E -O0 - < /dev/null > /tmp/O0.txt
$ gcc -dM -E -O3 - < /dev/null > /tmp/O3.txt
$ sdiff -s /tmp/O0.txt /tmp/O3.txt
#define __NO_INLINE__ 1 <
> #define __OPTIMIZE__ 1
Late answer - I found the other answers useful - and wanted to add a bit extra.
How do I dump preprocessor macros coming from a particular header file?
echo "#include <sys/socket.h>" | gcc -E -dM -
In particular, I wanted to see what SOMAXCONN was defined to on my system. I know I could just open up the standard header file, but sometimes I have to search around a bit to find the header file locations. Instead I can just use this one-liner:
$ echo "#include <sys/socket.h>" | gcc -E -dM - | grep SOMAXCONN
#define SOMAXCONN 128
$
链接地址: http://www.djcxy.com/p/85784.html
上一篇: 有什么区别
下一篇: GCC转储预处理器定义