C++编译问题,解决arm下链接静态库,引起的relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol错误

显示的完整错误如下:

relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `ZN2c43yml9free_implEPvmS1' which may bind externally can not be used when making a shared object; recompile with -fPIC

根据提示,在链接.a静态库时,应该在编译时加上参数-fPIC

然而CMake文件中已经有了

add_compile_options(-fPIC)

导致这个问题的根本原因在于,链接的.a文件在编译时没有加上-fPIC参数

所以找到.a文件的源码,并在编译时加上-fPIC,在链接时就没问题了

posted @ 2023-01-09 14:44  umichan  阅读(4675)  评论(0编辑  收藏  举报