Compiling with g++ 64 bit in redhat using eclipse.
使用eclipse在redhat中使用g++ 64位编译。
Compile Error: ../lib-EL5-64bit/libskd3_clnt_30134500.a(skd_clnt.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC
编译错误:../lib-EL5-64bit/ libskd3_clnt_30134500a . (skd_clnt.o):在创建共享对象时不能使用“本地符号”的重新定位R_X86_64_ 32。编译与fpic
Things I have tried I added -fPIC to both the c++ compiler flags, as well as the linker flags. It already existed in the compiler flags, i just moved it to directly after the g++, and at the end of the list.
我尝试过的东西都添加了-fPIC到c++编译器标志,以及链接器标志。它已经存在于编译器标志中,我只是将它直接移到g++之后,并在列表的末尾。
I've asked the creator of the .a library to recompile with -fPIC and it still gives the same error
我已经问了一个库的创建者用-fPIC重新编译,它仍然会给出同样的错误。
Is there any way to make sure that their library was compiled with -fPIC? Does the error message say that I need to compile my .so with -fPIC, or the .a file needs to be compiled with -fPIC? What else can I check?
有没有办法确保他们的图书馆是用-fPIC汇编的?错误消息是否说我需要编译my .so with -fPIC,或a文件需要用-fPIC编译?我还能检查什么?
Here is the make file (auto generated by eclipse)
这是make文件(由eclipse自动生成)
Make file:
使文件:
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include generic_d2s/subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: libFUSE.so
# Tool invocations
libFUSE.so: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
g++ -fPIC -L../../CRYPTOPP/lib-EL5-64bit -L../lib-EL5-64bit -Wl,-rpath /lib -shared -o"libFUSE.so" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(LIBRARIES)$(CPP_DEPS)$(CXX_DEPS)$(C_UPPER_DEPS) libFUSE.so
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
subdir.mk
subdir.mk
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../CRI.cpp
C_SRCS += \
../client_rsa.c
OBJS += \
./CRI.o
C_DEPS += \
./client_rsa.d
CPP_DEPS += \
./CRI.d
# Each subdirectory must supply rules for building sources it contributes
%.o: ../%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
g++ -D_TM_CDIR='"/proj/kronos/test/hho/testprograms/trunk/testmethods/FUSE"' -I../../CRYPTOPP/include/cryptopp -I"/opt/hp93000/soc/pws/lib" -I"/opt/hp93000/soc/com/include" -I/opt/hp93000/soc/prod_com/include -I/opt/hp93000/soc/prod_com/include/MAPI -I/opt/hp93000/soc/testmethod/include -O0 -g3 -Wall -c -fmessage-length=0 -shared -fPIC -Wreturn-type -Wmissing-braces -Wparentheses -Wswitch -Wunused-function -Wunused-label -Wunused-parameter -Wunused-variable -Wunused-value -Wunknown-pragmas -Wsign-compare -Wconversion -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
%.o: ../%.c
@echo 'Building file: $<'
@echo 'Invoking: GCC C Compiler'
gcc -D_TM_CDIR='"/proj/kronos/test/hho/testprograms/trunk/testmethods/FUSE"' -I/opt/hp93000/soc/prod_com/include -I/opt/hp93000/soc/prod_com/include/MAPI -I/opt/hp93000/soc/testmethod/include -I/opt/hp93000/soc/com/include -I/opt/hp93000/soc/pws/lib -O0 -g3 -Wall -c -fmessage-length=0 -fPIC -Wreturn-type -Wmissing-braces -Wparentheses -Wswitch -Wunused-function -Wunused-label -Wunused-parameter -Wunused-variable -Wunused-value -Wunknown-pragmas -Wsign-compare -Wconversion -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
objects.mk
objects.mk
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
USER_OBJS :=
LIBS := -lBB_IO_lib.0.1 -lskd3_clnt_30134500 -lcryptopp
sources.mk
sources.mk
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
O_SRCS :=
CPP_SRCS :=
C_UPPER_SRCS :=
C_SRCS :=
S_UPPER_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
CXX_SRCS :=
C++_SRCS :=
CC_SRCS :=
OBJS :=
C++_DEPS :=
C_DEPS :=
CC_DEPS :=
LIBRARIES :=
CPP_DEPS :=
CXX_DEPS :=
C_UPPER_DEPS :=
# Every subdirectory with source files must be described here
SUBDIRS := \
. \
generic_d2s \
1 个解决方案
#1
3
When you compile statically, the assembler instructions will assume certain things about the locality of code, e.g. any jump is within 4GB of the jumping/calling instruction. (Assuming 64b x86). Shared libraries may be loaded further away than 4GB, so that jump/call wont fit.
当您静态编译时,汇编指令将假定代码的位置,例如任何跳转都在4GB的跳转/调用指令之内。(假设64 b x86)。共享库可能比4GB加载得更远,所以跳/调用不适合。
When you compile with -fPIC (position independent code) - the compiler will ensure that the code and local data references are position indepdent, and arrange for calls/jumps outside of itself happen with the worst case/maximum addressing mode (eg full 64b).
当您使用- fpic(位置独立代码)编译时,编译器将确保代码和本地数据引用是不确定的,并且在最坏情况/最大寻址模式(如full 64b)的情况下,安排调用/跳出自身。
When you get this error, as you have, the static library cannot jump to the shared library - the shortcuts above were taken. The only solution is a recompile with -fPIC. (Technically, the 32-bit jump may only be 5 bytes but you need 9 bytes [1 opcode + 8 for the addr]; so no amount of assembler cleverness can work around this - not without some other dastardly operation, like using INT instructions to provide a short hand jump).
当您得到这个错误时,静态库不能跳转到共享库——上面的快捷方式被占用了。唯一的解决方案是用-fPIC重新编译。(从技术上讲,32位跳转可能只有5个字节,但您需要9个字节[1个opcode + 8用于addr];因此,任何数量的汇编器的聪明都不能解决这个问题——不是没有其他一些卑鄙的操作,比如使用INT指令来提供一个短的手跳。
Nowadays most everything can/should be compiled with -fPIC irrespective of being shared - unless performance is important.
现在大多数的东西都可以用- fpic编译,而不考虑共享-除非性能很重要。
#1
3
When you compile statically, the assembler instructions will assume certain things about the locality of code, e.g. any jump is within 4GB of the jumping/calling instruction. (Assuming 64b x86). Shared libraries may be loaded further away than 4GB, so that jump/call wont fit.
当您静态编译时,汇编指令将假定代码的位置,例如任何跳转都在4GB的跳转/调用指令之内。(假设64 b x86)。共享库可能比4GB加载得更远,所以跳/调用不适合。
When you compile with -fPIC (position independent code) - the compiler will ensure that the code and local data references are position indepdent, and arrange for calls/jumps outside of itself happen with the worst case/maximum addressing mode (eg full 64b).
当您使用- fpic(位置独立代码)编译时,编译器将确保代码和本地数据引用是不确定的,并且在最坏情况/最大寻址模式(如full 64b)的情况下,安排调用/跳出自身。
When you get this error, as you have, the static library cannot jump to the shared library - the shortcuts above were taken. The only solution is a recompile with -fPIC. (Technically, the 32-bit jump may only be 5 bytes but you need 9 bytes [1 opcode + 8 for the addr]; so no amount of assembler cleverness can work around this - not without some other dastardly operation, like using INT instructions to provide a short hand jump).
当您得到这个错误时,静态库不能跳转到共享库——上面的快捷方式被占用了。唯一的解决方案是用-fPIC重新编译。(从技术上讲,32位跳转可能只有5个字节,但您需要9个字节[1个opcode + 8用于addr];因此,任何数量的汇编器的聪明都不能解决这个问题——不是没有其他一些卑鄙的操作,比如使用INT指令来提供一个短的手跳。
Nowadays most everything can/should be compiled with -fPIC irrespective of being shared - unless performance is important.
现在大多数的东西都可以用- fpic编译,而不考虑共享-除非性能很重要。