tl;dr:问题在于解释为什么std::stringstream“失败”,以及为什么在链接到重新构建的c++_shared库时,std::stringstream以失败的方式失败(只需不做任何操作)。
一个最小的例子是:
std::stringstream ss;
ss << "Hello World";
__android_log_print(ANDROID_LOG_INFO,
"APP",
"Length: %i", ss.str().size());编译项目时
APP_STL := c++_shared
LIBCXX_FORCE_REBUILD := true输出为Length: 0。当使用APP_STL := c++_static或LIBCXX_FORCE_REBUILD := false时,stringstream按预期工作,以Length: 11作为输出。
我正在使用STL的许多部分,到目前为止我所看到的唯一显著的区别是这个沉默的NOP stringstream。我还通过修改libgl2jni NDK示例对此进行了测试,将Application.mk文件添加为:
NDK_TOOLCHAIN_VERSION := 4.8
APP_OPTIM := release
APP_STL := c++_shared
APP_ABI := armeabi-v7a #armeabi-v7a x86
APP_PLATFORM := android-19
LIBCXX_FORCE_REBUILD := true我在Nexus-4上测试了APP_OPTIM作为发布/调试、APP_STL作为c++_shared/c+_static和LIBCXX_FORCE_REBUILD作为真/假的各种排列,其中armeabi和armeabi-v7a都是目标ABI。其结果是:
|-------------+-----------+----------------------+---------+------------------|
| ABI | stl c++_? | LIBCXX_FORCE_REBUILD | optim | Result |
|-------------+-----------+----------------------+---------+------------------|
| armeabi | static | true | release | OK |
| | static | true | debug | OK |
| | static | false | release | BUILD FAILED [1] |
| | static | false | debug | BUILD FAILED [1] |
| | shared | true | release | NOP |
| | shared | true | debug | NOP |
| | shared | false | release | OK |
| | shared | false | debug | OK |
|-------------+-----------+----------------------+---------+------------------|
| armeabi-v7a | static | true | release | OK |
| | static | true | debug | OK |
| | static | false | release | OK |
| | static | false | debug | OK |
| | shared | true | release | NOP |
| | shared | true | debug | NOP |
| | shared | false | release | OK |
| | shared | false | debug | OK |
|-------------+-----------+----------------------+---------+------------------|1 /opt/android-ndk-r9d/sources/cxx-stl/llvm-libc++/libs/armeabi/libc++static.a(ios.o):/tmp/ndk-andrewhsieh/tmp/build-21097/build-libc++/ndk/sources/cxx-stl/llvm-libc++/libcxx/src/ios.cpp:function std::_1::ios_base::xalloc():error:未定义的对“__atomic_fetch_add_4”的引用
PS:确保在这些测试之间执行一个ndk-build clean。
的问题是:在这种情况下,有谁能对std::stringstream失败的原因给出一些见解,以及为什么只对流到它的任何数据执行NOP就会失败?
谢谢
发布于 2014-08-11 03:57:40
我无法回答为什么NOP发生在某些排列中。但我确实找到了构建失败的原因。
我的处境比你还糟。我经历了与使用c++_static和LIBCXX_FORCE_REBUILD默认值(false)相结合的构建失败,并且不知道为什么。
感谢您分享您对链接STL的各种排列的研究--我能够直接跳转到显著的文档中来修复构建错误。
如果你包括的话,你很可能需要libatomic。添加ndk-build的"LOCAL_LDLIBS += -latomic“
为了能够使用libatomic,您需要将NDK_TOOLCHAIN_VERSION设置为4.8
发布于 2015-11-11 10:24:38
请试试这个:
LOCAL_LDFLAGS += -Wl,--gc-sections代码片段似乎并没有真正调用atomic_fetch_add()。使用--gc-sections选项,链接器将从最终的可执行文件或共享库中删除未使用的代码和数据。因此,atomic_fetch_add()的依赖项可能会被删除。
“-章节”:ugn/Compilation-options.html
其他一些信息:https://code.google.com/p/android/issues/detail?id=68779
https://stackoverflow.com/questions/23041401
复制相似问题