Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the g++ -D flag do?

I am looking at a CFLAGS of -

CFLAGS=-g -w -D LINUX -O3 -fpermissive

in a Makefile. What does the -D flag do? I see on the man page that

-D name
    Predefine name as a macro, with definition 1. 

but I don't know how to interpret that. My interpretation is...its making LINUX a macro and only doing -03 and -fpermissive when in a linux environment. Is that right? If not, then what? Thanks for any help

like image 208
Sterling Avatar asked Apr 26 '12 16:04

Sterling


People also ask

What is G flag in Linux?

(debug) Inserting the `g' flag tells the compiler to insert more information about the source code into the executable than it normally would. This makes use of a debugger such as gdb much easier, since it will be able to refer to variable names that occur in the source code.

What is G option GCC?

-g requests that the compiler and linker generate and retain source-level debugging/symbol information in the executable itself.

What is option in GCC?

When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The "overall options" allow you to stop this process at an intermediate stage. For example, the -c option says not to run the linker.


2 Answers

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.

like image 194
Gabriel Southern Avatar answered Sep 24 '22 00:09

Gabriel Southern


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.

like image 45
jpalecek Avatar answered Sep 24 '22 00:09

jpalecek