A1A2A3A4
A1A2A3A4

Reputation: 453

What is the -DLINUX flag for gcc?

I have seen makefiles use the -DLINUX flag but can't find any documentation on it. Is there a place to find information on tools like 'gcc' that are more up-to-date than the officially released manuals?

Upvotes: 3

Views: 3559

Answers (4)

Tadeusz A. Kadłubowski
Tadeusz A. Kadłubowski

Reputation: 8363

It just defines the LINUX symbol for the C preprocessor.

Probably there are pieces of the code that look like:

#ifdef LINUX
    //Linux-specific code
#elif defined WINDOWS
    //Windows-specific code
#endif

Upvotes: 4

user3146587
user3146587

Reputation: 4320

It defines a preprocessor macro named LINUX. That's it. The macro itself, LINUX, is not a predefined one, it's probably used for a cross-platform codebase where specific sections of code are enabled for a Linux target. For this purpose, one could actually have re-used the predefined linux or __linux__ ones (see the output of gcc -dP -E - < /dev/null to get all the predefined macros on your system).

See http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/ for the standard documentation on gcc (that's obviously for GCC 4.8.2). To my knowledge, that's the best place to look for if this documentation is not already installed (or up-to-date) on your system.

Upvotes: 0

gturri
gturri

Reputation: 14629

According to man gcc:

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

Hence, it let define a constant from the compilation command line.

Upvotes: 1

toasted_flakes
toasted_flakes

Reputation: 2509

It's the -D option controlling the preprocessor. It defines the LINUX macro, that you can then use with #ifdef.

Upvotes: 2

Related Questions