# linux compiler #define?

This topic is 5407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Quick question...is there a standard defined symbol when compiling in linux? I mean something like
#ifdef _LINUX
//do linux stuff
#else //windows etc
//do other stuff
#endif


I thought there was a standard one but I've come across 3 or 4 in the past few days, and I'm getting tired of saying "#ifndef _WIN32" I've seen _LINUX, __LINUX__, _LINUX_, and just plain LINUX and linux

##### Share on other sites
I'm not sure if there is a "standard" one - as a matter of fact I doubt it - since I can't see OS macros being part of the language spec.

Since you're usually compiling with a makefile on linux anyways, just choose a single macro and stick with it - then add -D_LINUX or the like into the compile options - this is how most packages deal with this on linux I believe anyways.

If you want something "automatic" look into some of the standard headers on a linux box. Just be warned, those macros are probably not guaranteed to be in place - and eventually someone will probably complain about it not compiling on some really weird specialized system.

• 21
• 13
• 9
• 17
• 13