C++ 平台特定包括

标签 c++

我正在从事一个多平台项目。我想要一种简单快捷的方法来管理特定于操作系统的包含,最好不需要任何外部工具。

我想要这样的东西(我很清楚这是行不通的)

#define PLATFORM_A 1
#define PLATFORM_B 2

#ifndef TARGET_PLATFORM
//ERROR
#endif

#if TARGET_PLATFORM == PLATFORM_A
    #define DIR "a"
#elif TARGET_PLATFORM == PLATFORM_B
    #define DIR "b"

#define PLATFORM_INCLUDE(file) \
    #include "platforms/" DIR "/" file

最佳答案

我经常看到的一个设置如下:

// platform.h

#if defined PLATFORM_A
    #include "platform_a.h"
#elif defined PLATFORM_B
    #include "platform_b.h"
#else
    // #pragma error or whatever
#endif

然后在必要时#include "platform.h"

关于C++ 平台特定包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16551042/

相关文章:

c++ - ifstream 用于破坏散列字符串

C++//将getline输入与多字串进行比较?

c++ - 如何检查目录是文件还是文件夹?

c++ - 我应该如何共享数据结构

C++ const struct &variable 产生缺少的标签名称

c++ - 如何配置 Eclipse C 项目以接受 C++ 包含

c++ - 将 VC++ 内联汇编程序移植到 x64(__stdcall Hook )

c++ - 手动签署 PE 文件

java - JNI,在一个需要另一个的地方使用两个 .so 文件时出错

c++ - 使用流运算符构建错误