解决.a静态库,链接成一个.so动态库出现:
relocation R_X86_64_32 against `xxxxxxx' can not be used when making a shared object; 的错误。
在编译的时候出现relocation R_X86_64_32 against `.xxxxx' can not be used when making a shared object; 的错误。
原因是因为生成静态库时没有加 -fPIC 选项。
起因:
在Ubuntu中安装openssh时,编译makefile出现如下错误:
根据提示错误找到对应的的makefile(上图所示的时zlib-1.2.1.2文件夹中的makefile),打开所提示的makefile,找到“CFLAGS”变量,在该变量的后面加入“-fPIC”参数,如下所示:
CFLAGS += -fPIC # 静态库链接成.so动态库,编译静态库的时候需要加 -fPIC这个参数。
然后保存退出,重新编译即可。参考文档如下: