GCC dump preprocessor defines

后端 未结 6 2191
既然无缘
既然无缘 2020-11-22 14:28

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.

6条回答
  •  轮回少年
    2020-11-22 15:11

    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 " | gcc -E -dM -
    

    or (thanks to @mymedia for the suggestion):

    gcc -E -dM -include sys/socket.h - < /dev/null
    

    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:

    $ gcc -E -dM -include sys/socket.h - < /dev/null | grep SOMAXCONN
    #define SOMAXCONN 128
    $ 
    

提交回复
热议问题