2013-05-15 53 views
0

使用eclipse在redhat中編譯g ++ 64位。將靜態(.a)庫鏈接到共享庫(.so),出現錯誤「重定位R_X86_64_32S針對本地符號;使用-fPIC重新編譯」

編譯錯誤: ../lib-EL5-64bit/libskd3_clnt_30134500.a(skd_clnt.o):創建共享目標時針對`局部符號」重定位R_X86_64_32S不能使用;使用-fPIC重新編譯

我試過的東西 我在-cP編譯器標誌以及鏈接器標誌中都加了-fPIC。它已經存在於編譯器標誌中,我剛把它移到g ++之後,並在列表的末尾。

我問。一庫的創建者與-fPIC重新編譯,它仍然給出了同樣的錯誤

有沒有什麼辦法,以確保他們的圖書館與-fPIC編譯? 錯誤消息是否說我需要使用-fPIC編譯我的.so文件,或者需要使用-fPIC編譯.a文件? 我還能檢查什麼?

這裏是(Eclipse生成自動)make文件

Make文件:

################################################################################ 
# 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: [email protected]' 
    @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: [email protected]' 
    @echo ' ' 

# Other Targets 
clean: 
    -$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(LIBRARIES)$(CPP_DEPS)$(CXX_DEPS)$(C_UPPER_DEPS) libFUSE.so 
    [email protected] ' ' 

.PHONY: all clean dependents 
.SECONDARY: 

-include ../makefile.targets 

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"[email protected]" "$<" 
    @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"[email protected]" "$<" 
    @echo 'Finished building: $<' 
    @echo ' ' 

objects.mk

################################################################################ 
# Automatically-generated file. Do not edit! 
################################################################################ 

USER_OBJS := 

LIBS := -lBB_IO_lib.0.1 -lskd3_clnt_30134500 -lcryptopp 

來源.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 \ 
+0

存檔('.a')必須用'-fPIC'重新編譯。 –

回答

3

當您靜態編譯時,彙編程序指令將假設某些關於代碼局部性的事情,例如,任何跳轉都在跳轉/調用指令的4GB以內。 (假設64b x86)。共享庫可能會被加載遠離4GB,所以跳/呼叫不適合。

當您使用-fPIC(位置獨立代碼)進行編譯時,編譯器將確保代碼和本地數據引用位置獨立,並且在最壞情況/最大尋址模式下安排調用/例如完整的64b)。

當您遇到此錯誤時,靜態庫無法跳轉到共享庫 - 上述快捷方式已被採用。唯一的解決方案是用-fPIC重新編譯。 (從技術上講,32位跳轉可能只有5個字節,但你需要9個字節[addr + 1操作碼+8];所以沒有任何彙編程序聰明能夠解決這個問題 - 而不是沒有其他一些卑鄙的操作,如使用INT指令提供一個短手跳躍)。

如今,除非性能很重要,否則大多數情況下都可以/應該使用-fPIC進行編譯,而不管共享如何。

相關問題