美文网首页
编译错误 cannot locate symbol 查找原因

编译错误 cannot locate symbol 查找原因

作者: 爱玩保龄球 | 来源:发表于2020-09-08 10:35 被阅读0次
  • 遇到错误提示
   java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "post_onEvent" referenced by "/data/app/com.sina.weibo.medialive.landscape-R7fxpZBAyXPFfAnEbJXPRw==/lib/arm64/liblivepublisher.so"...
       at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
       at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
       at java.lang.System.loadLibrary(System.java:1667)
       at com.sina.weibo.medialive.landscape.LivePublisher.<clinit>(LivePublisher.java:72)
       at com.sina.weibo.medialive.landscape.MainActivity.<init>(MainActivity.java:49)
  • 查看符号表工具目录
android-ndk-r14b/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin
  • 查看符号表工具
# 工具使用命令
./aarch64-linux-android-readelf -s xxx/src/main/jniLibs/arm64-v8a/liblivepublisher.so | grep "post_onEvent"
   191: 000000000000e684   680 FUNC    GLOBAL DEFAULT   10 _Z12post_onEventiPc
   418: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND post_onEvent
  • 分析过程
    • _Z12post_onEventiPc 是c++ 的编译方式 (按照函数名参数)
    • post_onEvent 是c 的编译方式(按函数名)
    • "NOTYPE" 目前还不清楚怎么回事
  • 知识链接 extern c 的主要作用
  • 问题根源
#ifdef __cplusplus
extern "C" {
#include "common/define.h"  // 这个文件是c++ 声明函数用的,我放到了extern c 里面,这样导致编译链接按照c的方式处理了

#endif

#ifdef __cplusplus
}
#endif
  • 个人理解
  • 两个方式都编译进去了,但是System.loadLibrary 可能找c 的方式没有找到函数实现,如果理解不对的可以留言给我,谢谢。

相关文章

网友评论

      本文标题:编译错误 cannot locate symbol 查找原因

      本文链接:https://www.haomeiwen.com/subject/huddektx.html