简体   繁体   中英

GCC - Macro containing compilation flags

Is there any macro in GCC that contain compilation flags used to compile the program?

I want something like this:

printf("Compilation flags: %s", __FLAGS__);

To output for example:

Compilation flags: -02 -g

Short answer: No.

Slightly longer answer: Even if there was, your code would become non-portable. Projects needing this sort of functionality let the build system do it, eg by having all the flags in a CFLAGS variable in make and have a rule create a config.h putting all these flags in a #define there.

This probably won't be of much help, but GCC has the option -fverbose-asm ( https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html ) that will dump the command-line options used in the generated assembly as a comment.

Of course, that's only useful if you intend to read the generated assembly rather than directly assemble it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM