• Advertisement
Sign in to follow this  

Preprocessor macros to detect operating system?

This topic is 2460 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:



//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>
*/



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
Advertisement
#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

Share this post


Link to post
Share on other sites
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
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
Sign in to follow this  

  • Advertisement