Sign in to follow this  
Chrono1081

Preprocessor macros to detect operating system?

Recommended Posts

Chrono1081    108
Hi guys,

I have some header files that currently look like this:

[code]

//MAC OSX INCLUDES
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>

/*
//WINDOWS INCLUDES
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/freeglut.h>
*/
[/code]


I could have sworn there was a way to make a preprocessor macro that would automatically switch between the two depending on the system your on so you don't have to comment out the includes that are not for the OS you are currently using. For example, if I am on Windows just the "Windows includes" are seen by the compiler, if I'm on Mac, only the "Mac includes" are seen. Unfortunately I can't seem to find anything that works.

Does anyone have any idea how to do this? Is it possible? Any help would be greatly appreciated :)

Share this post


Link to post
Share on other sites
n3Xus    951
[code]#define OS_WINDOWS

#if defined (OS_WINDOWS)
#include <windowsStuff>
#endif

// mac stuff won't get included since only OS_WINDOWS is defined
#if defined (OS_MAC)
#include <macstuff>
#endif[/code]

Share this post


Link to post
Share on other sites
Buckeye    10747
In addition to n3Xus' comments, you should be able to set compiler defines such as WINDOWS, etc., in your project, rather than defining those types of variables in the project files themselves.


Share this post


Link to post
Share on other sites
Endurion    5407
Most compilers already set a specific define, look them up at this fantastic site: [url="http://predef.sourceforge.net/preos.html"]http://predef.sourceforge.net/preos.html[/url]

Share this post


Link to post
Share on other sites
Chrono1081    108
Thank you so much everyone! I never use preprocessor macros as I'm pretty much self taught and not many books cover them in detail, but I knew I remembered seeing one that switched between Windows and Mac. This will be very useful for a class project of mine, I am on a Mac and the rest of our group is on Windows.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this