[英]Link shared library with each other shared libraries c++
我已經成功創建了我的共享庫libA.so。
里面的所有類都有namspace common :: A.
ldd libA.so
linux-vdso.so.1 => (0x00007fffd632d000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f6497d19000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6497b03000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6497743000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6497447000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6498243000)
然后,我需要創建另一個使用A的庫B.所以我鏈接它(-lA和-L <path_to_A>)並使用_I /編譯。 內部的所有類都有namspace common :: B.
編譯並生成libB.so ,但是:
1) Elipse將紅色X放在我稱之為A方法的代碼中:
Multiple markers at this line
- Symbol '<A_method>' could not be resolved
- Function '<A_method>' could not be resolved
2)圖書館A似乎與B無關:
ldd libB.so
linux-vdso.so.1 => (0x00007fffbcbfe000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f695ca59000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f695c842000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f695c483000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f695bf7e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f695d1d9000)
我不明白為什么我沒有A的鏈接:
libA.so => .....
有任何想法嗎?
這是makefile(由eclipse自動生成):
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include src/network/mqtt/subdir.mk
-include src/data/subdir.mk
-include subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: libB.so
# Tool invocations
libB.so: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
g++ -L/path_where_is_A_so/ -shared -o "libB.so" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(LIBRARIES)$(CC_DEPS)$(C++_DEPS)$(C_UPPER_DEPS)$(CXX_DEPS)$(OBJS)$(CPP_DEPS)$(C_DEPS) libB.so
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
如果你的libB沒有在libA中使用任何東西,鏈接器可能會放棄鏈接到libA(取決於鏈接器標志--as-needed
是否是工具鏈中的默認值。)
要強制libB鏈接到力霸,指定標志-Wl,--no-as-needed
出庭-lA
。
如果您使用的是MakeFile,那么請執行以下操作:
xxxxxx_la_SOURCES = $(FILES)
xxxxxx_la_CFLAGS = $(CFLAGS)
xxxsxx_la_LDFLAGS = $(location_of_so_file)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.