【问题标题】:What are the preprocessor definitions for mobile platforms?移动平台的预处理器定义是什么?
【发布时间】:2013-09-11 15:11:49
【问题描述】:

我正在编写一个需要在 Windows、Mac、Linux、Android、iOS 上运行的库。我已经有了以下定义:

#if defined(_WIN32) || defined(__WIN32__)

    // Windows
    #define SYSTEM_WINDOWS

#elif defined(linux) || defined(__linux)

    // Linux
    #define SYSTEM_LINUX

#elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh)

    // MacOS
    #define SYSTEM_MACOS

#elif defined(__ANDROID__)

    // Android
    #define SYSTEM_ANDROID

#else

    // Unsupported system
    #error This operating system is not supported

#endif

但我不确定要在 iOS 上使用什么。

【问题讨论】:

  • 那么 TARGET_OS_IPHONE 可用于任何 iOS 设备?似乎有点太明确了。
  • 这里有更详细的描述。 nadeausoftware.com/articles/2012/01/…this SO question 还讨论了如何区分版本。
  • @Mike 你似乎并不介意__ANDROID__ 用于任何 Android 设备。这有什么不同?
  • iPhone 不是操作系统。如果检测 Android 的唯一方法是使用 GALAXY_TAB,我也会质疑其中的逻辑。感谢 Wandering Logic,这是一个很好的链接。

标签: c++ cross-platform c-preprocessor


【解决方案1】:

在 /usr/include/TargetConditionals.h 中,您可以找到 TARGET_OS_IPHONE 的定义,对于 iOS 和 iOS 模拟器,它的值都是 1。

请参阅以下链接以确定如何检测多个平台的操作系统:

Detecting the OS Using Predefined Macros

【讨论】:

    猜你喜欢
    • 2010-11-10
    • 2016-07-04
    • 1970-01-01
    • 2011-07-25
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    • 2020-10-12
    • 2011-02-28
    相关资源
    最近更新 更多