首页 > 代码库 > linux 生成动态库时提示relocation R_X86_64_32 against `.rodata' can not be used when making a shared object;

linux 生成动态库时提示relocation R_X86_64_32 against `.rodata' can not be used when making a shared object;

linux生成动态库时遇到了relocation R_X86_64_32 against `.rodata‘ can not be used when making a shared object; recompile with -fPIC错误。

由于我的系统是AMD64位的,所以需要在编译的时候添加 -fPIC选项


解决方法:

例如:

g++ -c -fPIC head.cpp    生成head.o

g++ -fpic -shared -o libfun.so head.o