Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ #ifdef Mac OS X question

I am fairly new to C++. I am currently working on a group project and we want to make our classes compatible with both the lab computers (Windows) and my computer (Mac OS X).

Here is what we have been putting at the top of our files:

#ifdef TARGET_OS_X #    include <GLUT/glut.h> #    include <OpenGL/OpenGL.h> #elif defined _WIN32 || defined _WIN64 #    include <GL\glut.h> #endif 

I realize this question has been asked before but my searches have been giving me conflicting answers such as "_MAC", "TARGET_MAC_OS", "MACINTOSH", etc. What is the current and correct declaration to put in the #ifdef statement to make this compatible with Mac? Right now it is not working.

Thank you!

like image 486
Kirsty Avatar asked Jul 23 '11 19:07

Kirsty


1 Answers

According to this answer:

#ifdef __APPLE__     #include "TargetConditionals.h"     #ifdef TARGET_OS_IPHONE          // iOS     #elif TARGET_IPHONE_SIMULATOR         // iOS Simulator     #elif TARGET_OS_MAC         // Other kinds of Mac OS     #else         // Unsupported platform     #endif #endif 

So in short:

#ifdef __APPLE__     #include "TargetConditionals.h"     #ifdef TARGET_OS_MAC         #include <GLUT/glut.h>         #include <OpenGL/OpenGL.h>     #endif #elif defined _WIN32 || defined _WIN64     #include <GL\glut.h> #endif  
like image 182
orlp Avatar answered Sep 19 '22 09:09

orlp