relocation R_X86_64_32 against XXXXX can not be used when making a shared object;recompile with -fPI

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

很可能是在编译的时候CFLAGS 配置里没有 -fPIC 
或是在生成其他.o文件时没有 配置 -fPIC

eg

[root@localhost ppserver]# tree
.
├── bin
│ ├── PPServer
│ └── tcSend
├── build.sh
├── etc
│ └── conf.yaml
├── lib
│ ├── libconf.so
│ ├── libhsm.so
│ └── libkfpubs.so
├── make_eg
│ ├── makefile-bin
│ ├── makefile-lib
│ ├── makefile-src_obj_dir
│ └── makefile-srcsubobj
├── makefile
├── obj
│ ├── Application.o
│ ├── makefile
│ ├── PPServer
│ │ ├── MainFrm.o
│ │ ├── makefile
├── src
│ ├── include
│ ├── mainFrm
│ │ ├── MainFrm.cpp
│ │ ├── MainFrm.h
│ │ ├── makefile
│ │ ├── makefile-bin
│ ├── makefile
│ ├── PosPhoneProtocol
│ │ ├── Application.cpp
│ │ ├── makefile

在src/PosPhoneProtocol/Application.cpp 生成 obj/Application.o 使用 
gcc -c Application.cpp -o obj/Application.o

在src/mainFrm/MainFrm.cpp 生成 obj/PPServer/MainFrm.o 使用
gcc -c MainFrm.cpp -o obj/PPServer/MainFrm.o

进入到obj/PPServer 生成.so时
gcc -fPIC -shared obj/PPServer/MainFrm.o obj/Application.o -o libppserver.so

时会报这个错误。

因为在生成.o时没有加 -fPIC 。以前不报错也可以是在CFLAGS 回默认加上配置。

gcc编译参数-fPIC的一些问题
http://blog.sina.com.cn/s/blog_54f82cc201011op1.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值