本文转自:https://blog.csdn.net/hanyulongseucas/article/details/87715186
感谢原作者分享。

问题描述:
执行make命令编译c++文件时,遇到link error:
/usr/bin/x86_64-linux-gnu-ld: /opt/lib/xxxx.a(xxxx.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5’ can not be used when making a PIE object; recompile with -fPIC

以为是gcc、cmake、make等版本问题不对,降低了版本,问题仍然存在。后来搜到上面的文章,按照其中方法尝试后问题解决。具体如下:

参考上面的文章,这是因为原 xxxx.a 库在编译时未加 -fPIC选项,但是当前程序编译时却需要这个选项。解决方法是:
在CMakeLists.txt文件中增加定义:
SET(CMAKE_EXE_LINKER_FLAGS " -no-pie")

再重新编译,问题解决。

Logo

更多推荐