Sign in to follow this  

Preprocessor macros to detect operating system?

This topic is 2389 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 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
[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
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

This topic is 2389 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.

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