android ndk编译C++ 的undefined reference to '__cxa_end_cleanup'及 __gxx_personality_v0问题

出现这两个错误主要是由于缺少stl支持导致的。
android 的ndk默认是不带 stl相关属性的
这就导致他编译C++代码的时候有时候会链接失败,报一些函数找不到。

比如这两个:
__cxa_end_cleanup 
和   __gxx_personality_v0   

这些stl相关的库不在$(NDK_ROOT)/platforms/android-9/arch-arm/usr/lib里面,而在$(NDK_ROOT)/sources/cxx-stl 下面你用grep 可以看到 
hl@hl-VirtualBox:/opt/android-ndk-r8c/sources/cxx-stl$ grep -rnH "__cxa_end_cleanup"  ./  
Binary file ./gnu-libstdc++/4.4.3/libs/armeabi-v7a/libsupc++.a matches
Binary file ./gnu-libstdc++/4.4.3/libs/armeabi-v7a/libgnustl_shared.so matches
Binary file ./gnu-libstdc++/4.4.3/libs/armeabi-v7a/libgnustl_static.a matches
Binary file ./gnu-libstdc++/4.4.3/libs/armeabi/libsupc++.a matches
Binary file ./gnu-libstdc++/4.4.3/libs/armeabi/libgnustl_shared.so matches
Binary file ./gnu-libstdc++/4.4.3/libs/armeabi/libgnustl_static.a matches
Binary file ./gnu-libstdc++/4.6/libs/armeabi-v7a/libsupc++.a matches
Binary file ./gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_shared.so matches
Binary file ./gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_static.a matches
Binary file ./gnu-libstdc++/4.6/libs/armeabi/libsupc++.a matches
Binary file ./gnu-libstdc++/4.6/libs/armeabi/libgnustl_shared.so matches
Binary file ./gnu-libstdc++/4.6/libs/armeabi/libgnustl_static.a matches

如果你用ndk自带的nm命令查看这个 libsupc++.a就会发现它里面是有__cxa_end_cleanup 这个函数定义的
hl@hl-VirtualBox:/opt/android-ndk-r8c/sources/cxx-stl$ arm-linux-androideabi-nm ./gnu-libstdc++/4.6/libs/armeabi-v7a/libsupc++.a | grep __cxa_end_cleanup 
         U __cxa_end_cleanup
00000000 T __cxa_end_cleanup
         U __cxa_end_cleanup
         U __cxa_end_cleanup
         U __cxa_end_cleanup
         U __cxa_end_cleanup
         U __cxa_end_cleanup
         U __cxa_end_cleanup
         U __cxa_end_cleanup
         U __cxa_end_cleanup
         U __cxa_end_cleanup
         U __cxa_end_cleanup
         U __cxa_end_cleanup

所以我们在编译C++代码的时候如果遇到这类问题,就在Android.mk里面加上:

STL_PATH=$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a
以及
LOCAL_LDLIBS += -L$(STL_PATH) -lsupc++
即可解决这个问题
再次感谢此文作者,说的很详细,对我启发很大
http://blog.csdn.net/andyhuabing/article/details/8591459  
  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值