适用于 Android 的 uSTL 或 STLPort?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1650963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
uSTL or STLPort for Android?
提问by Andrew Garrison
I'm working with the Android NDK, and since it does not currently support the STL, I was wondering if there are any brilliant people out there who have had success with this, or know which is better suited for the Android platform: uSTL or STLPort.
我正在使用 Android NDK,由于它目前不支持 STL,我想知道是否有任何聪明的人在这方面取得了成功,或者知道哪个更适合 Android 平台:uSTL 或STL端口。
EDIT: Looks like another option may be CrystaX .NET.
编辑:看起来另一个选项可能是CrystaX .NET。
From their website:
从他们的网站:
...customized distribution of Android NDK r3 which I have rebuilt from official sources. Support of C++ exceptions, RTTI and Standard C++ Library added.
...我从官方来源重建的 Android NDK r3 的定制发行版。添加了对 C++ 异常、RTTI 和标准 C++ 库的支持。
采纳答案by jsding
STLport supported since Android2.3 now!!!
从Android2.3开始支持STLport!!!
回答by Stéphane
Ports of STL are officially available in the Android NDK from version r5on. It can be used either as a static or shared library. The following implementations are available prebuilt with the NDK :
从 r5 版本开始,Android NDK中正式提供STL 端口。它可以用作静态或共享库。可以使用 NDK 预构建以下实现:
- STLport, based on v5.2.0 :
- static
stlport_static
: use if you have only one dynamic library in your project. - dynamic
stlport_shared
: to use if you have more than one dynamic library in your project.
- static
- GNU libstdc++
system
(static library)
- STLport,基于 v5.2.0 :
- static
stlport_static
:如果您的项目中只有一个动态库,请使用。 - dynamic
stlport_shared
: 如果您的项目中有多个动态库,则使用。
- static
- GNU libstdc++
system
(静态库)
The recommended, easy way to use itat build time is by defining APP_STL in the Application.mk, like this :
在构建时使用它推荐的简单方法是在 Application.mk 中定义 APP_STL,如下所示:
APP_STL := stlport_static
And if you want to rebuild it (this is notnecessary), define STLPORT_FORCE_REBUILD in your Application.mk :
如果您想重建它(这不是必需的),请在您的 Application.mk 中定义 STLPORT_FORCE_REBUILD :
STLPORT_FORCE_REBUILD := true
The unit test framework for STLport is also available.
STLport 的单元测试框架也可用。
Current limitations for STLport:
STLport 的当前限制:
- C++ Exceptions not supported
- RTTI not supported
- "Probable bugs" in support for
wchar_t
and locales
- 不支持 C++ 异常
- 不支持 RTTI
- 支持
wchar_t
和语言环境中的“可能的错误”
Various Links :
各种链接:
Documentation is available in the NDK packages at the following locations (there may be more) :
NDK 包中的文档位于以下位置(可能还有更多):
- docsCPLUSPLUS-SUPPORT.html
- sources/cxx-stl/stlport
- sources/cxx-stl/gnu-libstdc++
- docsCPLUSPLUS-SUPPORT.html
- 来源/cxx-stl/stlport
- 来源/cxx-stl/gnu-libstdc++
Download NDK + docs here; file bugs here
Below is an excerpt from docs/CPLUSPLUS-SUPPORT.html (from NDK docs, r5)
以下是 docs/CPLUSPLUS-SUPPORT.html 的摘录(来自 NDK 文档,r5)
III. Selecting the C++ Standard Library Implementation:
三、选择 C++ 标准库实现:
By default, the headers and libraries for the minimal C++ runtime system library (/system/lib/libstdc++.so) are used when building C++ sources.
默认情况下,在构建 C++ 源代码时使用最小 C++ 运行时系统库 (/system/lib/libstdc++.so) 的头文件和库。
You can however select a different implementation by setting the variable APP_STL to something else in your Application.mk, for example:
但是,您可以通过在 Application.mk 中将变量 APP_STL 设置为其他内容来选择不同的实现,例如:
APP_STL := stlport_static
APP_STL := stlport_static
To select the static STLport implementation provided with this NDK. Value APP_STL values are the following:
选择随此 NDK 提供的静态 STLport 实现。值 APP_STL 值如下:
system -> Use the default minimal C++ runtime library. stlport_static -> Use STLport built as a static library. stlport_shared -> Use STLport built as a shared library.
系统 -> 使用默认的最小 C++ 运行时库。stlport_static -> 使用作为静态库构建的 STLport。stlport_shared -> 使用作为共享库构建的 STLport。
WARNING: IMPORTANT CAVEAT
警告:重要警告
AT THE MOMENT, OUR STLPORT IMPLEMENTATION DOES NOT SUPPORT EXCEPTIONS
AND RTTI. PLEASE BE SURE TO NOT USE -fexceptions OR -frtti IN ALL
MODULES THAT USE IT.
WARNING: END OF IMPORTANT CAVEAT
警告:重要警告结束
"stlport_shared" is preferred if you have several shared libraries in your project that use the C++ STL, because it avoids duplication of functions and more importantly of global variables (e.g. std::cout) in each one of them, which can have surprising results.
如果您的项目中有多个使用 C++ STL 的共享库,则首选“stlport_shared”,因为它避免了函数的重复,更重要的是避免了每个函数中的全局变量(例如 std::cout)重复,这可能会产生令人惊讶的结果.
On the other hand, you will have to load it explicitely when starting your application, as in the following example:
另一方面,您必须在启动应用程序时显式加载它,如下例所示:
static {
System.loadLibrary("stlport_shared");
System.loadLibrary("foo");
System.loadLibrary("bar");
}
Where both "libfoo.so" and "libbar.so" depend on "libstlport_shared.so".
“libfoo.so”和“libbar.so”都依赖于“libstlport_shared.so”。
Note that the shared library's name if "libstlport_shared.so" to avoid naming conflicts with certain Android system images which include a system-level libstlport.so (which happens to not be ABI-stable and cannot be used from NDK-generated machine code).
请注意,共享库的名称如果为“libstlport_shared.so”,以避免与某些包含系统级 libstlport.so 的 Android 系统映像发生命名冲突(这恰好不是 ABI 稳定的,并且不能从 NDK 生成的机器代码中使用) .
"stlport_static" is preferred if you have only one shared library in your project: only the STL functions and variables you actually need will be linked to your machine code, reducing its code size, and you won't need to load the dynamic stlport_shared at startup.
如果您的项目中只有一个共享库,则首选“stlport_static”:只有您实际需要的 STL 函数和变量才会链接到您的机器代码,从而减少其代码大小,并且您无需在以下位置加载动态 stlport_shared启动。
IV. STLport-specific issues:
四、STLport 特定的问题:
This NDK provides prebuilt static and shared libraries for STLport, but you can force it to be rebuilt from sources by defining the following in your environment or your Application.mk before building:
此 NDK 为 STLport 提供预构建的静态和共享库,但您可以通过在构建之前在您的环境或 Application.mk 中定义以下内容来强制从源重新构建它:
STLPORT_FORCE_REBUILD := true
STLport is licensed under a BSD-style open-source license. See sources/cxx-stl/stlport/README for more details about the library.
STLport 是在 BSD 风格的开源许可下获得许可的。有关该库的更多详细信息,请参阅 sources/cxx-stl/stlport/README。
V. Future Plans:
五、未来计划:
- Make STLport compatible with C++ exceptions and RTTI
- Full GNU libstdc++ support
- uSTL support?
- 使 STLport 与 C++ 异常和 RTTI 兼容
- 完整的 GNU libstdc++ 支持
- uSTL 支持吗?
回答by Nemanja Trifunovic
Just note that uSTL deviates from the standard quite a bit. For instance, it assumes UTF-8 encoding for std::string. Still looks interesting, though...
请注意,uSTL 与标准有很大差异。例如,它假定 std::string 使用 UTF-8 编码。不过看起来还是挺有意思的……
回答by Stjepan Rajko
I recently came across some helper scripts and a port of STLport for Android, by John Ripley.
我最近遇到了 John Ripley编写的一些辅助脚本和 STLport for Android 端口。
There is also a related blog post with instructions of how to set it up.
还有一篇相关的博客文章,其中包含如何设置的说明。
I suppose that might make it easier to go with STLport.
我想这可能会使使用 STLport 更容易。
回答by Andrew
this is how I configured STLPort to work with Android Froyo.
这就是我将 STLPort 配置为与 Android Froyo 一起使用的方式。
// The code
// The set of definitions and includes for STLPort
// They used defined() instead of #ifdef.
#define _STLP_HAS_INCLUDE_NEXT 1
#define _STLP_USE_MALLOC 1
#define _STLP_USE_NO_IOSTREAMS 1
#include <stl/config/_android.h>
#include <map>
#include <string>
// Android.mk
# For Android STL support
LOCAL_C_INCLUDES += external/stlport/stlport
LOCAL_SHARED_LIBRARIES += libstlport
Andrew
安德鲁
回答by Gamma Draconis
Note that the git repository mention in the link from Stjepan Rajko's answer no longer exists. Alternative sources are on anddevand, via git, at git://stlport.git.sourceforge.net/gitroot/stlport/stlport. I found the latter at a longer discussionof using both stlport and boost under Android.
请注意,Stjepan Rajko 的回答链接中提到的 git 存储库不再存在。替代来源在anddev 上,通过 git,在 git://stlport.git.sourceforge.net/gitroot/stlport/stlport。我在关于在 Android 下同时使用 stlport 和 boost的较长讨论中发现了后者。
Since first answering this question, I have gotten the anddev STLPort to work with my library that also calls boost, including the problematic shared_ptr. For details of my solution see this question.
自从第一次回答这个问题以来,我已经让 anddev STLPort 与我的库一起工作,该库也调用了 boost,包括有问题的 shared_ptr。有关我的解决方案的详细信息,请参阅此问题。