简体   繁体   English

跨平台如何成为标准C ++库?

[英]How cross platform is the standard C++ library?

Is the C++ standard library (eg std::string stream) available on iOS and Android (using the JNI/NDK)? iOS和Android上是否可以使用C ++标准库(例如std :: string stream)(使用JNI / NDK)? If so: 如果是这样:

To what degree is it supported? 它支持的程度如何? How are desktop specific features such as the console handled? 桌面特定功能如控制台如何处理? How fast/reliable is it? 它有多快/可靠? How many other mobile platforms is it available on? 有多少其他移动平台? Can I count on not having to modify much code using the std library when porting to mobile platforms (such as iOS)? 在移植到移动平台(例如iOS)时,我可以依靠使用std库修改很多代码吗?

The C++ standard library is available on both. 两者都提供C ++标准库。 Furthermore, iOS has had C++11 for quite a while. 此外,iOS已经有了很长一段时间的C ++ 11。

Both platforms - fundamentally being POSIX based - have the concept of console IO, but neither provides access to it in the user interface, and on neither can you (at least out of the box) run a console application directly. 这两个平台 - 基本上都是基于POSIX的 - 具有控制台IO的概念,但它们都不能在用户界面中提供对它的访问,也不能(至少开箱即用)直接运行控制台应用程序。

As a consequence, it's obvious that you can't use console IO for any kind of user-interaction with your application - unless that is, you build it using the platform's user-interface API. 因此,很明显您不能将控制台IO用于与您的应用程序进行任何类型的用户交互 - 除非您使用平台的用户界面API构建它。

In terms of portability, there shouldn't be any issues on either platform - it's the GNU Std G++ library on Android and the Clang C++ library on iOS. 在可移植性方面,两个平台都不应该有任何问题 - 它是Android上的GNU Std G ++库和iOS上的Clang C ++库。 Portability is a non-issue on iOS, but you'll probably have fun building JNI bindings for Android. 在iOS上,可移植性不是问题,但您可能很有兴趣为Android构建JNI绑定。

In reality though, you're only ever able to build the back-ends of applications in C++. 但实际上,您只能用C ++构建应用程序的后端。 All user interfaces will be distinctly non portable, and will generally need to be implemented in the language of the UI framework. 所有用户界面都是明显不可移植的,并且通常需要以UI框架的语言实现。

Windows Phone 8 allows native Apps, and C++ seems to be the language of choice to implement them in. BlackBerry OS 10 is fundamentally QNX under the hood, which is also POSIX compliant. Windows Phone 8允许本机应用程序,而C ++似乎是实现它们的首选语言.BlackBerry OS 10基本上是QNX,它也是POSIX兼容的。

As far as I can tell, standard libraries should be standard across all platforms. 据我所知,标准库应该是所有平台的标准库。 Now their internal implementation may or will vary but they should perform the task for which they were introduced. 现在他们的内部实现可能会或将会有所不同,但他们应该执行它们被引入的任务。

Generally std lib is very efficient, fast and well tested so it should be reliable. 通常std lib非常有效,快速且经过良好测试,因此它应该是可靠的。

The actual catch is that std lib should be included with C++ implementation but it is totally upto the vendor implementing C++ whether std lib included or not. 实际的问题是std lib应该包含在C ++实现中,但无论是否包含std lib,它都完全取决于实现C ++的供应商。 Even if they don't include std lib there is a high chance that you can find alternative implementation for that platform. 即使它们不包含std lib,您也很有可能找到该平台的替代实现。 Then all you have to do is link that library with your code. 然后,您所要做的就是将该库与您的代码链接起来。

Assuming that there is a C++ compiler supporting major features. 假设有一个支持主要功能的C ++编译器。

Even if that is not possible, you can always port the required std functions to that specific platform as a custom lib. 即使这是不可能的,您也可以将所需的std函数作为自定义lib移植到该特定平台。

Hope this helps, 希望这可以帮助,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM