0

I'm developing an API multi platform in C language and I need to know if there is a way to know which OS is compiling it.

For example, through an pre compilation directive like that follows:

#ifdef LINUX
#include<linuxlib.h>
#elif OSX
#include<osxlib.h>
#elif WINDOWS
#include<rwindowslib.h>
Filipe
  • 1,189
  • 4
  • 15
  • 30

1 Answers1

1

Here is some info:

#if defined(__LINUX__)
// Linux, Android, MacOS
#if defined(__ANDROID__)
// Android
#elif defined(__APPLE__)
// MacOS
#else
// Linux or its flavor
#endif
#elif defined(WIN32)
// Windows targets must have WIN32 (_WIN32)
#endif

Here is a large list of what can be defined on various platforms: http://sourceforge.net/p/predef/wiki/OperatingSystems/

Valeri Atamaniouk
  • 5,125
  • 2
  • 16
  • 18