Reputation: 13618
In a makefile I work on, gcc is used with the -D XOPEN_SOURCE=500 and -D_BSD_SOURCE
options. gcc --help
does not tell me what these are; a quick google search didn't help either. I'm quite a newbie with gcc, could someone give me a hint?
Upvotes: 0
Views: 720
Reputation: 5198
-D
sets a define. It's like adding a header file that contains:
#define XOPEN_SOURCE 500
#define _BSD_SOURCE 1
You can then use #ifdef _BSD_SOURCE
to enable conditional compilation of certain part of the code.
Upvotes: 1
Reputation: 16675
-D
is used to set defines. The source code you are compiling most likely is using those defines to include specific header files.
Think of -D
as doing the same thing as:
#define XOPEN_SOURCE 500
#define _BSD_SOURCE 1
at the top of the file it is currently compiling.
Upvotes: 2
Reputation: 52217
According to the GCC documentation ("3.11 Options Controlling the Preprocessor"), the -D
switch defines the macros XOPEN_SOURCE
and _BSD_SOURCE
with the values 500
and 1
respectively. It's as though you have this code at the beginning of all the source files you pass to GCC:
#define XOPEN_SOURCE 500
#define _BSD_SOURCE 1
Build scripts usually take advantage of the compiler's ability to "insert" macros like these to "communicate" to the source code details about the platform being targeted (e.g. operating system version).
The "opposite" command-line switch for -D
is -U
, which #undef
s a macro.
Most (if not all) modern C/C++ compilers include similar switches. For example, Visual C++ compilers accept the /D
compiler switch, which essentially serves the same purpose as GCC's -D
switch.
For future reference, the GCC option index is great if you need to look up compiler switches for the GCC compiler.
Upvotes: 4
Reputation: 651
These do not nothing for gcc. These are definitions like similar you have in your .c, .cpp or .h files:
#define XOPEN_SOURCE 500
#define _BSD_SOURCE
Upvotes: 1