场景:

二进制Link-->动态库-->第三方静态库

Linux环境中需要动态库链接第三方的静态库


错误:

/usr/bin/ld: ../../3rdpart/x64/muduo/lib/libbase.a(AsyncLogging.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC

../../3rdpart/x64/muduo/lib/libbase.a: could not read symbols: Bad value

collect2: error: ld returned 1 exit status


解决方法:

重新编译静态库第三方的静态库

在makefile 中添加-fPIC


查看编译期参数是否缺少 -fPIC , 不仅是共享库,静态库有时也需要有 -fPIC参数