c++ #ifdef Mac OS X 问题

标签 c++ macos compatibility conditional-compilation

我对 C++ 还很陌生。我目前正在做一个小组项目,我们想让我们的类(class)与实验室计算机 (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 兼容?现在它不工作。

谢谢!

最佳答案

根据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

简而言之:

#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 

关于c++ #ifdef Mac OS X 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6802903/

相关文章:

c++ - boost::static_visitor 作为映射值

C++ regex_search 在 C 样式数组上进行匹配

c++ - -std=c++ 98 和 OS X 10.10

macos - 构建和安装 x86_64 而不是 i386 的 Brew 应用程序?

css - Safari 'on hover' 和 'click' 图像叠加错误

objective-c - Mac OS X 和 Linux 兼容性的最佳编译语言

c++ - 此 C++ 语句中 'operator' 的含义

c++ - 在 SFML 中获取文本的尺寸

objective-c - Cocoa:如果用户没有执行任何操作,则隐藏 NSWindow

将 fxFlex 与 mat-form-field 一起使用时,Angular Material Flex-layout 元素不会出现在 Internet Explorer 11 中