Linker errors in Android NDK (undefined reference to `__cxa_end_cleanup')
在 Android 中移植一个库(该库 使用了 libstlport )时 产生如下错误:
./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'
-
After reading
android-ndk/docs/CPLUSPLUS-SUPPORT.html
I found that there a couple more libraries that I can link to:C++ C++ Standard Exceptions RTTI Library system no no no gabi++ no yes no stlport no yes yes gnustl yes yes yes
This stops my linker errors (and pushes the build onto a new set of errors :))
Application.mk
APP_STL := gnustl_static
-
Take a look here: Linux C++: Linker is outputting strange errors.
In Android's Application.mk this would be:
APP_CPPFLAGS := –frtti
-
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++
参考链接:http://quabr.com/9226513/linker-errors-in-android-ndk-undefined-reference-to-cxa-end-cleanup
相关文章
- 【控件显示】Android中控件的显示(visible、invisible、gone)
- android 平台签名
- android 因为没有赋null,报以下错:has already been added to the window manager
- android.view.WindowManager$BadTokenException: Unable to add window
- 1-3年Android开发工程师面试经验分享,安卓系列学习进阶视频
- [Android Studio] Using NDK to call OpenCV
- Failed to apply plugin [id 'com.android.application'] 和 Could not find com.android.tools.build:gradle:2.XX的最正确的解决方法
- Failed to install the following Android SDK packages as some licences have not been accepted.
- 【已解决】Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory
- Android异步载入全解析之使用多线程
- Android studio ElasticDownloadView
- 【Android-tips】 Unable to execute dex: Multiple dex files define 解决方法
- Process 'command '/Users/lidaqiang/Library/Android/sdk/build-tools/27.0.3/aapt'' finished with non-zero exit value 1
- Android优化——UI优化(三)使用ViewStub延迟加载
- android的操作系统 根据进程的优先级 把进程分为了若干个等级
- 解决Android的adb命令行报错Permission denied
- android 代码设置空间高度
- build opencv in termux, when build opencv_waldboost_detector error in undefined reference to '__android_log_print' #2172
- 【9】Android组件系列----ContentProvider内容提供者+ 原生数据库Sqlite操作
- failed to apply plugin [id 'com.android.library']
- Android - IOExceptionConnection to xxx refused.
- 【错误记录】Android Studio 配置 AspectJ 报错 ( Failed to create Jar file C:xxxaspectjtools-1.8.10.jar. )
- 实现Android底部导航栏
- android Git命令家底儿及Git数据通信原理详解
- 【我的Android进阶之旅】解决SVN Cleanup错误: Failed to run the WC DB work queue associated with
- 我的Android进阶之旅------>Android无第三方Jar包的源代报错:The current class path entry belongs to container ...的解决方法
- 我的Android进阶之旅------>解决如下错误failed to copy 'Settings2.apk' to '/system/app//Settings2.apk': Read-only