Page 1 of 1

GCC OS Specific Define List..

Posted: Tue Sep 26, 2006 10:15 pm
by Brynet-Inc
I've written applications and have ran into a few instances when using #ifdef's are very handy..

Here is a list of GCC define's that will help you too implement support for many OS's in a single codebase.

(The list..)
__FreeBSD__
__OpenBSD__
__NetBSD__
__bsdi__
__DARWIN__
__DragonFly__
__sun
__linux__
__CYGWIN__

Also, if you use MinGW..
__MINGW32__
__MINGW32_MAJOR_VERSION
__MINGW32_MINOR_VERSION

The host GCC defines the appropriate one automatically!, This means you can support multiple Operating systems without having to define OS specific flags like -DLINUX manually..

Example on how it works.. input.c
#include <stdio.h>

int main(void)
{
#ifdef __OpenBSD__
printf("Yay, Your using OpenBSD..\n");
#else
printf("Ah, Not running OpenBSD eh?..\n");
#endif
}

(just gcc -o output input.c)

I'm guessing a lot of the developers know of this already, But others may find this list fairly helpful as it can take awile trying to google them all ;). If you have any other handy GCC defines please post them here for reference :).

Re:GCC OS Specific Define List..

Posted: Fri Sep 29, 2006 9:59 am
by df
99% of the time i need to differentiate between compilers rather than OSii.

_MSC_VER
__WATCOMC__
__GNUC__
__TINYC__

Posted: Sat Oct 28, 2006 9:40 pm
by Brynet-Inc
I've recently found this, Contains all kinds of C define marco's..

Take a peek 8)

http://predef.sourceforge.net/index.php