[英]Link shared library with each other shared libraries c++
I've successfully create my shared library, libA.so . 我已经成功创建了我的共享库libA.so。
All classes inside, have namspace common::A 里面的所有类都有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)
Then, I need to create another library, B, that uses A. So I link it (-lA and -L< path_to_A >) and also compile with _I/. 然后,我需要创建另一个使用A的库B.所以我链接它(-lA和-L <path_to_A>)并使用_I /编译。 All classes inside, have namspace common::B
内部的所有类都有namspace common :: B.
Compile and make libB.so , but: 编译并生成libB.so ,但是:
1) Elipse put red X in code where I call A methods: 1) Elipse将红色X放在我称之为A方法的代码中:
Multiple markers at this line
- Symbol '<A_method>' could not be resolved
- Function '<A_method>' could not be resolved
2) Library A seems not linked to B: 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)
I can't understand why I don't have a link to A: 我不明白为什么我没有A的链接:
libA.so => .....
Any ideas? 有任何想法吗?
This is makefile (autogenerated by eclipse): 这是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
If your libB doesn't use anything in libA, the linker might discard linking to libA (depending on whether the linker flag --as-needed
is the default in your toolchain.) 如果你的libB没有在libA中使用任何东西,链接器可能会放弃链接到libA(取决于链接器标志
--as-needed
是否是工具链中的默认值。)
To force libB to link to libA, specify the flag -Wl,--no-as-needed
to appear before -lA
. 要强制libB链接到力霸,指定标志
-Wl,--no-as-needed
出庭-lA
。
If you are using MakeFile then do things like this: 如果您使用的是MakeFile,那么请执行以下操作:
xxxxxx_la_SOURCES = $(FILES)
xxxxxx_la_CFLAGS = $(CFLAGS)
xxxsxx_la_LDFLAGS = $(location_of_so_file)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.