最近在编译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
也是可以的。当前还没有论证。



7491

被折叠的 条评论
为什么被折叠?



