我正在尝试为我正在做的项目创建一个共享对象 (myLib.so)。并且我创建了一个单独的 Eclipse“项目”来尝试使用/测试共享对象——它们在同一个工作区中。
当我为共享对象(使用 boost 库线程等)编译项目时,一切都会编译文件并且我没有收到任何错误。
当我编译测试程序并尝试将其链接到 myLib.so 时,出现以下错误:
/path/lib.so: undefined reference to `boost::thread::interrupt()'
/path/lib.so: undefined reference to `vtable for boost::detail::thread_data_base'
/path/lib.so: undefined reference to `boost::detail::thread_data_base::~thread _data_base()'
/path/lib.so: undefined reference to `typeinfo for boost::detail::thread_data_base'
/path/lib.so: undefined reference to `boost::thread::start_thread()'
/path/lib.so: undefined reference to `boost::this_thread::sleep(boost::posix_time::ptime const&)'
我不确定我是否在编译 myLib.so 错误,或者我的测试项目设置是否不正确。正如我所说,当我单独编译 myLib.so 时,一切似乎都可以正常工作,但是当我编译测试程序(由于某种原因重新编译 myLib.so)时,它似乎出错了。
我将 myLib.so 的源代码包含在测试项目的编译器中,并将 myLib.so 包含在测试项目的链接器库中。
如果有人可以提供一些帮助,将不胜感激。需要更多信息请询问。
谢谢,
额外信息:
为 lib.so 制作文件
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include *several-different-files*.mk mostly blank, LIB is blank
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: libmyLIB.so
# Tool invocations
libmyLIB.so: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
g++ -shared -o "libmyLIB.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) libPS.so
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
用于测试设置的 Makefile
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include 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: TestingmyLIB
# Tool invocations
TestingmyLIB: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: Cross G++ Linker'
g++ -L"/PATH" -o TestingLIB$(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(C++_DEPS)$(OBJS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) TestingLIB
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
还有一个 mk 文件,用于测试设置参考 (objects.mk) 的 makefile 包含 LIBS := -lmyLIB