GCC - Macro containing compilation flags

Viewed 987

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
2 Answers

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, e.g. 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

Related