【爬坑记录】ncnn移植到Android上出现的编译问题

【爬坑记录】ncnn移植到Android上出现的编译问题

背景:因为项目中使用的ncnn版本过早,希望编译一下最新版本,观察速度是否有提升,编译时出现如下报错:

报错1:
*/ncnn-20191113/src/allocator.h:63: error: undefined reference to 'posix_memalign'

*/ncnn-20191113/src/allocator.h:63: error: undefined reference to 'posix_memalign'

*/ncnn-20191113/src/allocator.h:63: error: undefined reference to 'posix_memalign'

*/ncnn-20191113/src/allocator.h:63: error: undefined reference to 'posix_memalign'

clang++: error: linker command failed with exit code 1 (use -v to see invocation)
examples/CMakeFiles/faceid_example.dir/build.make:171: recipe for target 'examples/faceid_example' failed
  • 问题成因:使用的编译选项Android_PLATFORM过低,Android_PLATFORM = android-14,修改到 Android_PLATFORM = android-19,问题得以解决;
报错2:
/home/sbb/opensource/ncnn/ncnn-20191113/ncnn-20191113/src/datareader.cpp:93: error: undefined reference to 'AAsset_seek'
/home/sbb/opensource/ncnn/ncnn-20191113/ncnn-20191113/src/datareader.cpp:94: error: undefined reference to 'AAsset_getBuffer'
/home/sbb/opensource/ncnn/ncnn-20191113/ncnn-20191113/src/datareader.cpp:112: error: undefined reference to 'AAsset_seek'
/home/sbb/opensource/ncnn/ncnn-20191113/ncnn-20191113/src/datareader.cpp:120: error: undefined reference to 'AAsset_read'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
examples/CMakeFiles/faceid_example.dir/build.make:171: recipe for target 'examples/faceid_example' failed

  • 解决思路:因为本来项目是好的,现在因为更新ncnn导致了这个问题,第一反应是ncnn的编译选项是否有变化,重新编译了一下,貌似还是不行;使用了如下命令:
readelf -a ncnn.a |grep AAsset

发现:

readelf -a libncnn.a |grep AAsset
Relocation section '.rel.text._ZN4ncnn26DataReaderFromAndroidAssetC2EP6AAsset' at offset 0x37d4 contains 1 entries:
Relocation section '.rel.ARM.exidx.text._ZN4ncnn26DataReaderFromAndroidAssetC2EP6AAsset' at offset 0x37dc contains 2 entries:
00000024  00008e0a R_ARM_THM_CALL    00000000   AAsset_seek
0000002c  00008f0a R_ARM_THM_CALL    00000000   AAsset_getBuffer
00000080  00008e0a R_ARM_THM_CALL    00000000   AAsset_seek
00000008  0000910a R_ARM_THM_CALL    00000000   AAsset_read

ncnn该有的库都是有的,最后定位到,是编译的可执行文件需要依赖Android 库;即这样:

target_link_libraries(example  ufacedet ${OpenCV_LIBS} android)# 需要加上最后一项的Android依赖库;

至此,问题得以解决;
参考链接:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值