zupazt3
zupazt3

Reputation: 1046

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

Upvotes: 6

Views: 1989

Answers (2)

Kyrill
Kyrill

Reputation: 3819

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

Upvotes: 0

user2371524
user2371524

Reputation:

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.

Upvotes: 5

Related Questions