C ++平台支持

时间:2020-05-14 20:20:23

标签: c++ linux windows macos macros

我正计划使我的C ++应用程序与Windows / Mac / Linux兼容。此刻,我想到了这个“代码”:

#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) || defined(__NT__)
   #include <Windows.h>
#elif defined(__APPLE__) || defined(__MACH__)
   #include <TargetConditionals.h>
   #if TARGET_IPHONE_SIMULATOR == 1
       #error "IOS simulator is not supported!"
   #elif TARGET_OS_IPHONE == 1
       #error "IOS is not supported!"
   #elif TARGET_OS_MAC == 1
       //MAC??????
   #else
       #error "Unknown Apple platform!"
#endif

#else
   #error "The platform you are currently using is not compatible!"
#endif

我不知道我是否正确实现了Windows,但至少我知道要包括哪些内容。所以我的问题是:

  • 使用Mac系统库需要导入什么内容?
  • 如何实现对Linux的支持以及使用他的库需要包括哪些内容?

我需要系统库,因为后来我计划根据系统的库制作一个窗口类,我想您可以在Windows上做到这一点,但是我不确定是否可以在linux / mac上做到这一点。

更新#1:
好的,所以我弄清楚了要使用哪些宏,但是我应该包括哪些库?

#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__CYGWIN__) || defined(__CYGWIN32__)
#define PLATFORM_WINDOWS
#include <Windows.h>

#elif defined(__APPLE__) && defined(__MACH__)
#include <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR == 1
#define PLATFORM_IPHONE_SIMULATOR
#error "Iphone simulator environment is not compatible!"
#elif TARGET_OS_IPHONE == 1
#define PLATFORM_IPHONE
#error "Iphone environment is not compatible!"
#elif TARGET_OS_MAC == 1
#define PLATFORM_MACOS
//what do I need to include here???
#endif
#elif defined(__ANDROID__)
#define PLATFORM_ANDROID
#error "Android environment is not compatible!"
#elif defined(__linux__) || defined(__linux) || defined(linux)
#define PLATFORM_LINUX
//what do i need to include here???
#else
#error "The platform you are currently using is not compatible!"
#endif

0 个答案:

没有答案