Jump to content
  • Advertisement
Sign in to follow this  
Q-Parser

How to distinguish Linux from Win using macros?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there! I'm curious about how to make my C code distinguish whether I'm compiling under Windows or Linux. For example there's "conio.h" under win but there isn't in linux. I know that it's done using #ifdef macros but have no idea how to do that. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
most win32 projects define _WIN32 so set up a simple app like a hello world you can do:


#include <stdio.h>
#include <stdlib.h>

#ifdef _WIN32
#include <windows.h>
#endif

// I think __linux__ is the common define for linux or __GNUC__
#ifdef __linux__
#include <somelinuxheader.h>
#endif




Thats the way I've seen it done in the MOD I work on in my spare time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!