c++ #ifdef Mac OS X 问题
我对 C++ 相当陌生。我目前正在开展一个小组项目,我们希望使我们的课程与实验室计算机 (Windows) 和我的计算机 (Mac OS X) 兼容。
以下是我们放在文件顶部的内容:
#ifdef TARGET_OS_X
# include <GLUT/glut.h>
# include <OpenGL/OpenGL.h>
#elif defined _WIN32 || defined _WIN64
# include <GL\glut.h>
#endif
我意识到这个问题以前曾被问过,但我的搜索给出了相互矛盾的答案,例如“_MAC”、“TARGET_MAC_OS”、“MACINTOSH”等。要放入 #ifdef 语句中以使其与 Mac 兼容的最新且正确的声明?现在它不起作用。
谢谢你!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 这个答案:
简而言之:
According to this answer:
So in short:
这取决于编译器。
#ifdef __APPLE__
适用于 gcc。It depends on the compiler.
#ifdef __APPLE__
works for gcc.据 Microsoft 称,
_WIN32
将涵盖 32 位和 64 位版本的 Windows。并且__APPLE__
适用于 Clang(至少在 Mavericks 中)。因此,编写上面 ifdef 的一种正确方法是:According to Microsoft,
_WIN32
will cover both the 32-bit and 64-bit versions of Windows. And__APPLE__
works for Clang (at least in Mavericks). So one correct way to write the ifdefs above is:小修正:#ifdef TARGET_OS_MAC 在 OS X 和 iOS 上都将始终为 true,因为它根据平台定义为 0 或 1,但是当定义 APPLE 时,TARGET_OS_MAC 也会被定义,因此在 #ifdef APPLE 中检查它是没有价值的。
您可能想改用#if TARGET_OS_MAC。所有 TARGET_* 宏都相同。
Small correction: #ifdef TARGET_OS_MAC will get you always true on both OS X and iOS, as it is defines either 0 or 1 depending on platform, but when APPLE is defined, TARGET_OS_MAC is defined as well, so checking it inside the #ifdef APPLE is worthless.
You might want to use #if TARGET_OS_MAC instead. Same for all TARGET_* macros.