Android中链接带符号库 ld.lld: error: undefined symbol

最近在编译so库的时候出现一个so库链接的问题:

ld.lld: error: undefined symbol: JniHelper::attachJVM()

这个类是在另外的一个带符号的so中。

怀疑是这个so的问题,查看之下发现.a和so正常编译。打开so查看符号发现也是在的。但是就是链接不上,cmake中也是有声明且都include了头文件和link了相关的so库。

既然编译没有问题,当前代码检查下来也没有问题。那可能就是cmake编译的时候和so切实没有做链接。这个方面需要有空去研究一下,由于时间问题就没进一步去研究了。理论上来说应该是可以的。当前采取了规避的方案,将这个error忽略掉。

在cmkae中添加参数:

set(CMAKE_MODULE_LINKER_FLAGS   "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--gc-sections,--unresolved-symbols=ignore-all")
set(CMAKE_SHARED_LINKER_FLAGS   "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections,--unresolved-symbols=ignore-all")

关于这个参数的解释如下:

‘ignore-all’

   Do not report any unresolved symbols.

‘report-all’

   Report all unresolved symbols. This is the default.

‘ignore-in-object-files’

   Report unresolved symbols that are contained in shared libraries, but ignore them if they come from regular object files.

‘ignore-in-shared-libs’

   Report unresolved symbols that come from regular object files, but ignore them if they come from shared libraries. This can be useful when creating a dynamic binary and it is known that all the shared libraries that it should be referencing are included on the linker’s command line.

当然,在网上查资料的时候说是

--allow-shlib-undefined

也是可以的。当前还没有论证。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值