学习笔记:relocation R_X86_64_32 against `.rodata' can not be used when making a shared object;
2016-09-09 14:48
726 查看
解决多个.a静态库,链接成一个.so动态库出现:
relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; 的错误。
我的总目标是:写一个mainApi.cpp的文件,这个文件提供API给外部用户使用。mainApi.cpp需要依赖其他模块生成的静态库(在lib文件下)。将mainApi.cpp编译
链接成一个.so动态库共外部使用。在编译的时候出现relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; 的错误。
原因是因为生成静态库时没有加 -fPIC 选项。
问题解决是如下(红色字体部分):
ifeq ($(MK_STATIC_LIB),no)
TARGET = libSendMsgModel.so
CFLAGS += -fPIC # 静态库链接成.so动态库,编译静态库的时候需要加 -fPIC这个参数。
else
TARGET = libSendMsgModel.a
endif
看下最后的实现目标(在主目录下生成libSendMsgModel.so文件):
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/29/07fbcc3b286012d0ad5b926ef2daf672)
看看lib下的文件:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/29/e6099ab8ac13bb03ef10c1c4abc975ff)
主目录下的Makefile:
relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; 的错误。
我的总目标是:写一个mainApi.cpp的文件,这个文件提供API给外部用户使用。mainApi.cpp需要依赖其他模块生成的静态库(在lib文件下)。将mainApi.cpp编译
链接成一个.so动态库共外部使用。在编译的时候出现relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; 的错误。
原因是因为生成静态库时没有加 -fPIC 选项。
问题解决是如下(红色字体部分):
ifeq ($(MK_STATIC_LIB),no)
TARGET = libSendMsgModel.so
CFLAGS += -fPIC # 静态库链接成.so动态库,编译静态库的时候需要加 -fPIC这个参数。
else
TARGET = libSendMsgModel.a
endif
看下最后的实现目标(在主目录下生成libSendMsgModel.so文件):
看看lib下的文件:
主目录下的Makefile:
XX = g++ AR = ar ARFLAG = -rcs CFLAGS = -g CLIBS = -L./lib/ -lSender -lReceiver -lResponser -lListener -lLogout -lpthread -lrt SUBDIRS = ./logout ./receiver ./responser ./sender ./listener # INCLUDE = a.h b.h ... can't be defined like "INCLUDE = ./*.h" INCLUDES = $(wildcard ./include/*.h ./sender/*.h ./receiver/*.h ./responser/*.h) #指定头文件目录,代码中就不需要把头文件的完整路径写出来了 INCLUDE_DIRS = -I./include -I./sender/ -I./receiver/ -I./responser/ -I./listener -I./logout OBJECTS = mainApi.o export XX CFLAGS AR ARFLAG ifeq ($(MK_STATIC_LIB),no) TARGET = libSendMsgModel.so CFLAGS += -fPIC # 静态库链接成.so动态库,编译静态库的时候需要加 -fPIC这个参数。 else TARGET = libSendMsgModel.a endif ifeq ($(MK_STATIC_LIB),no) $(TARGET) : $(OBJECTS) $(SUBDIRS) $(XX) $(CFLAGS) -shared -fPIC $< -o $@ $(CLIBS) # $< 表示依赖列表的第一个 也就是 $(OBJECTS) $(OBJECTS) : %.o : %.cpp $(XX) -c $(CFLAGS) $< -o $@ $(INCLUDE_DIRS) else $(TARGET) : $(OBJECTS) $(SUBDIRS) $(AR) $(ARFLAG) $@ $< # $< 表示依赖列表的第一个 也就是 $(OBJECTS) $(OBJECTS) : %.o : %.cpp $(XX) -c $(CFLAGS) $< -o $@ $(INCLUDE_DIRS) endif $(SUBDIRS):ECHO +$(MAKE) -C $@ ECHO: @echo $(SUBDIRS) @echo begin compile .PHONY : clean clean: for dir in $(SUBDIRS);\ do $(MAKE) -C $$dir clean||exit 1;\ done rm -rf $(TARGET) $(OBJECTS) ./lib/*.a
相关文章推荐
- 关于/usr/local/lib/libz.a(zutil.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC解决办法
- relocation R_X86_64_32 against `.rodata' can not be used when making a shared object;
- 编译程序遇到问题 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;
- relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recom
- 编译动态库出现问题relocation R_X86_64_32 against `a local symbol' 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;recompile with -fPI
- libavcodec/mqc.o: relocation r_x86_64_32 against `.rodata' can not be used when making a shared obje
- CentOS-6.3 编译erlang-otp 17.0 报relocation R_X86_64_32 against `OPENSSL_ia32cap_P' can not be used when making a shared object; recompile with -fPIC错误
- jsoncpp relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; ……
- relocation R_X86_64_32S against `_nc_globals' can not be used when making a shared object; recompile
- LibXML Compile Error: relocation R_X86_64_32 against `a local symbol' can not be used when making a
- relocation R_X86_64_32S against `a local symbol’ can not be used when making a shared object; recomp
- .libs/alloc.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared
- relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared objec
- 交叉编译出现a local symbol' can not be used when making a shared object的解决方法
- 加入ffmpeg静态库的错误can not be used when making a shared object; recompile with -fPIC
- gcc报错 can not be used when making a shared object; recompile with -fPIC
- can not be used when making a shared object; recompile with -fPIC
- can not be used when making a shared object; recompile with -fPIC