Android NDK 中的链接器错误(对“__cxa_end_cleanup”的未定义引用)
添加同事的一组代码后,我得到了这个输出:
./obj/local/armeabi/objs/jniWrapper/native.o: In function `_Vector_base':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_vector.h:73: undefined reference to `__cxa_end_cleanup'
./obj/local/armeabi/objs/jniWrapper/native.o:(.ARM.extab.text._ZNSt6vectorIhSaIhEEC1ERKS1_[std::vector<unsigned char, std::allocator<unsigned char> >::vector(std::vector<unsigned char, std::allocator<unsigned char> > const&)]+0x0): undefined reference to `__gxx_personality_v0'
./obj/local/armeabi/objs/jniWrapper/native.o: In function `std::__node_alloc::deallocate(void*, unsigned int)':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_alloc.h:161: undefined reference to `__cxa_end_cleanup'
./obj/local/armeabi/objs/jniWrapper/native.o:(.ARM.extab.text._ZNSt4priv12_String_baseIcSaIcEED2Ev[std::priv::_String_base<char, std::allocator<char> >::~_String_base()]+0x0): undefined reference to `__gxx_personality_v0'
./obj/local/armeabi/objs/jniWrapper/native.o: In function `basic_string':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_string.c:643: undefined reference to `__cxa_end_cleanup'
这是因为我无法访问正确的 STL。
据我所知,我只能选择三个(stlport_static
、stlport_shared
、system
),由 APP_STL := stlport_static< 设置/code> 在
Application.mk
中。
NDK 是否还有其他可用的库?
I'm getting this output after adding in a set of code from a colleague:
./obj/local/armeabi/objs/jniWrapper/native.o: In function `_Vector_base':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_vector.h:73: undefined reference to `__cxa_end_cleanup'
./obj/local/armeabi/objs/jniWrapper/native.o:(.ARM.extab.text._ZNSt6vectorIhSaIhEEC1ERKS1_[std::vector<unsigned char, std::allocator<unsigned char> >::vector(std::vector<unsigned char, std::allocator<unsigned char> > const&)]+0x0): undefined reference to `__gxx_personality_v0'
./obj/local/armeabi/objs/jniWrapper/native.o: In function `std::__node_alloc::deallocate(void*, unsigned int)':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_alloc.h:161: undefined reference to `__cxa_end_cleanup'
./obj/local/armeabi/objs/jniWrapper/native.o:(.ARM.extab.text._ZNSt4priv12_String_baseIcSaIcEED2Ev[std::priv::_String_base<char, std::allocator<char> >::~_String_base()]+0x0): undefined reference to `__gxx_personality_v0'
./obj/local/armeabi/objs/jniWrapper/native.o: In function `basic_string':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_string.c:643: undefined reference to `__cxa_end_cleanup'
This is caused because I don't have access to the correct STL.
To my knowledge there are only three I can choose from (stlport_static
, stlport_shared
, system
) as set by APP_STL := stlport_static
in Application.mk
.
Is there another library available to the NDK?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
阅读完 android-ndk/docs/CPLUSPLUS-SUPPORT.html 后,我发现还有几个可以链接到的库:
这会阻止我的链接器错误(并将构建推送到一组新的错误上) :))
Application.mk
After reading
android-ndk/docs/CPLUSPLUS-SUPPORT.html
I found that there a couple more libraries that I can link to:This stops my linker errors (and pushes the build onto a new set of errors :))
Application.mk
看一下这里:Linux C++:链接器正在输出奇怪的错误。
在 Android 的 Application.mk 中,这将是:
Take a look here: Linux C++: Linker is outputting strange errors.
In Android's Application.mk this would be:
您可以通过添加编译器选项
-lsupc++
来解决此问题。编辑:
原因:您的代码使用 C++ 异常机制,编译器会自动生成 try/catch/finally 块隐藏代码,这些代码又在某处调用 __cxa_end_cleanup 。
lsupc++ 意味着链接到 libsupc++.a
解决此问题的另一种方法是向 gcc 添加 -fno-exceptions 选项,这显然意味着禁用异常处理程序机制。
顺便说一句,您还应该添加 -fno-rtti 以避免其他可能遇到的编译错误,这是因为
所有 android 的 C++ 类都是在类内存布局中没有动态类型信息的情况下编译的。
总之,您应该使用以下选项组合之一:
1. -fno-rtti -fno-例外
2.-fno-rtti-lsupc++
You can fix this problem by adding the compiler option
-lsupc++
.Edited:
The reason: your code is using C++ exception mechanism which compiler automatically generate try/catch/finally block hidden code which in turn call __cxa_end_cleanup somewhere.
lsupc++ means link to libsupc++.a
Another way to resolve this problem is add -fno-exceptions option to gcc which obviously means disable exception handler mechanism.
BTW, you should also add -fno-rtti to avoid other maybe-encountered compilation error, this is because
all android's C++ class is compiled without dynamic type info in class memory layout.
In a word, you shoud use one of these option combos:
1. -fno-rtti -fno-exceptions
2. -fno-rtti -lsupc++
就我而言,当我将
-fexceptions
添加到编译器选项时,会出现对__cxa_end_cleanup
的未定义引用的错误。删除该选项时,未定义的引用消失,但这意味着您必须从异常语句中清除代码。In my case, the error undefined reference to
__cxa_end_cleanup
shows up when I add-fexceptions
to the compiler options. When removing that option, the undefined ref goes away, but that means you have to clear your code from exception statements.对我来说,这意味着添加 -fno-rrti 和 -fno-exceptions,然后在处理这两个问题的代码中删除“throw char*”。
for me that meant adding -fno-rrti and -fno-exceptions then getting rid of "throw char*" in the code which took care of both.