C ++识别运行平台(Android,iOS等) [英] C++ identify running platform (Android, iOS, etc.)

查看:269
本文介绍了C ++识别运行平台(Android,iOS等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个多平台项目的一部分(到目前为止,是Android和iOS),我们共享一个通用的C ++代码库,以满足数学和算法要求.

As part of a multi-platform project (Android & iOS so far), we share a common C++ codebase for mathematical and algorithmic requirements.

作为Android开发人员,我在使用同事在iOS项目中使用的标准库(STL)时遇到了一些问题.

As the Android developper, I am facing several problems using the Standard Library (STL) that my collegue uses in the iOS Project.

在我的build.gradle> android.ndk中,我使用:cppFlags += "-std=c++11"stl = 'gnustl_shared'

In my build.gradle > android.ndk I use : cppFlags += "-std=c++11" and stl = 'gnustl_shared'

作为示例,我不能使用原始STL中的std::nth_element()std::sort(),而必须包括bits/algorithmfwd.hbits/stl_algo.h.

As examples, I cannot use std::nth_element() or std::sort() from the original STL, I have to include either : bits/algorithmfwd.h or bits/stl_algo.h.

我去了include <bits/stl_algo.h>,到目前为止一切都很好.

I went for include <bits/stl_algo.h> and so far so good.

问题是,我们共享此代码库,我想知道是否可以使用标志来标识运行平台,以便代码动态使用正确的包含.

Problem is, we share this code base and I would like to know if we can use flags to identify the running platform so that the code dynamically uses the correct include.

感谢您的帮助!

@ andreas-reiff在他的回答中注意到的尚不清楚,我确实正在寻找要在头文件中使用的标志,以便在编译时(而不是在运行时)执行正确的包含.

As noticed by @andreas-reiff in his answer it is uncleared that I am indeed looking for the flags to use in headers files so that the proper include is performed at compiled time (and not at runtime).

如前所述,当前平台是iOS和Android.哪些标志可以帮助我们识别这些平台?

As stated before, the current platforms are iOS and Android. Which flags can help us identify these platforms ?

推荐答案

根据此页面,这是您需要的:

#ifdef __ANDROID__
    // Android Headers
#elif __APPLE__
    // iOS Headers
#endif

这篇关于C ++识别运行平台(Android,iOS等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆