What does the g++ -D flag do? What does the g++ -D flag do? linux linux

What does the g++ -D flag do?


It is equivalent to adding the statement #define LINUX 1 in the source code of the file that is being compiled. It does not have any effect on other compilation flags. The reason for this is it's an easy way to enable #ifdef statements in the code. So you can have code that says:

#ifdef LINUX   foo;#endif

It will only be enabled if that macro is enabled which you can control with the -D flag. So it is an easy way to enable/disable conditional compilation statements at compile time without editing the source file.


It doesn't have anything to do with -O3. Basically, it means the same as

#define LINUX 1

at the beginning of the compiled file.