Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the -D compiler flag C++ (clang, GNU, MSVC)

Okay I am assuming that the -D prefix means #define whatever variable name is followed by it, however I cannot find any documentation on this makefile feature for compiler flags.

CXX=clang -DTHISISPREPROCESSORVARIABLE

So -DTHISISPREPROCESSORVARIABLE in the make process would define the preprocessor variable THISISPREPROCESSORVARIABLE and would make the follow cout compiled.

#ifdef THISISPREPROCESSORVARIABLE
     std::cout << "this should exist with the -D" << endl;
#endif

Is this the right assumption? It seems to work, just can anyone confirm this -D is referring to #define (anyone have any links to some makefile docs that can fill in all these commands definitions?)

like image 699
Danoli3 Avatar asked Oct 25 '25 03:10

Danoli3


1 Answers

GCC, MSVC, and Intel, all have this flag documented, and Clang just uses GCC flags by default. I just found it on Clang's help page waaaay at the bottom (for clang-cl for windows), and harmic found it more clearly here for linux.

Execute clang-cl /? to see a list of supported options:
/D <macro[=value]> Define macro

harmic observes that these are compiler flags, and have nothing at all to do with makefiles, which is why you can't find it in the makefile docs. These flags can be put inside a makefile which will pass them to the compiler, but are not part of makefiles.

like image 171
Mooing Duck Avatar answered Oct 26 '25 18:10

Mooing Duck