虽然对此有很多疑问,但我找不到解决问题的正确方法。我在项目中使用libboost_system
,并在makefile中添加Libs:=libconfig++ libboost_thread libboost_system
,但它仍然无法运作。
我机器的环境:
- Ubuntu 14.04.5 LTS
- gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
- libboost_1.54
到目前为止,我已尝试过以下
g++ test.cpp -g -o main -lboost_system -lboost_thread
放在Lib的末尾。它仍然得到了同样的错误。libbost_system
,我不知道如何添加这个定义,所以我最终无法解决问题。我项目的部分makefile如下所示:
#define BOOST_ERROR_CODE_HEADER_ONLY
我收到的错误如下:
SOURCE_DIR := src
COMPILER := g++
BINARY_DIR := bin/lrelease
CPPFLAGS := -Wall -g -O3 -std=c++11
LIBS := -lpthread -lboost_thread -lconfig++ -lboost_system
COMPILE.cpp = $(COMPILER) $(CFLAGS) $(CPPFLAGS) -c
LINK.cpp = $(COMPILER) $(LIBS)
%.o: %.cpp
#$(call make-depend,$<,$@,$(subst .o,.d,$@))
$(COMPILE.cpp) $< -o $@
# $(call source-dir-to-binary-dir, directory-list)
source-dir-to-binary-dir = $(addprefix $(BINARY_DIR)/,$1)
# $(call source-to-object, source-file-list)
source-to-object = $(call source-dir-to-binary-dir, $(subst .cpp,.o,$1))
# $(subdirectory)
subdirectory = $(patsubst %/module.mk,%, \
$(word \
$(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
define make-depend
g++ -MM \
-MF$3 \
-MP \
-MT$2 \
$(CFLAGS) \
$(CPPFLAGS) \
$(TARGET_ARCH) \
$1
endef
# $(call make-library, library-name, source-file-list)
define make-library
libraries += $(BINARY_DIR)/$1
sources += $2
$(BINARY_DIR)/$1: $(call source-dir-to-binary-dir, $(subst .cpp,.o,$2))
$(AR) $(ARFLAGS) $$@ $$^
endef
# $(call make-program, program-name, library-list, source-file-list)
define make-program
programs += $(BINARY_DIR)/$1
sources += $3
$(BINARY_DIR)/$1: $(call source-dir-to-binary-dir, $(subst .cpp,.o,$3) $2 )
$(LINK.cpp) -o $$@ $$^ -lpthread
endef
# $(compile-rules)
define compile-rules
$(foreach f,$(local_src),$(call one-compile-rule,$(call source-to-object,$f),$f))
endef
# $(call one-compile-rule, binary-file, source-file)
define one-compile-rule
$1: $2
$(call make-depend,$2,$1,$(subst .o,.d,$1))
$(COMPILE.cpp) -o $1 $2
endef
# then the output dirs and make clean
#
#
添加或不添加g++ -lpthread -lboost_thread -lconfig++ -lboost_system -o bin/lrelease/ buildmyProjectFromN3 bin/lrelease/BuildmyProjectFromN3/BuildmyProject.o bin/lrelease/libmyProject.a -lpthread
bin/lrelease/libmyProject.a(myProjectBuilder.o):(.gcc_except_table+0x48c): undefined reference to `typeinfo for libconfig::FileIOException'
bin/lrelease/libmyProject.a(myProjectBuilder.o): In function `boost:: thread_exception::thread_exception(int, char const*)':
/usr/include/boost/thread/exceptions.hpp:51: undefined reference to `boost::system::system_category()'
bin/lrelease/libmyProject.a(myProjectBuilder.o): In function `boost:: condition_error::condition_error(int, char const*)':
/usr/include/boost/thread/exceptions.hpp:84: undefined reference to `boost: : system::system_category()'
bin/lrelease/libmyProject.a(myProjectBuilder.o): In function `interruption_checker':
/usr/include/boost/thread/pthread/thread_data.hpp:187: undefined reference to `boost::detail::get_current_thread_data()'
bin/lrelease/libmyProject.a(myProjectBuilder.o): In function `boost:: condition_variable::wait(boost::unique_lock<boost::mutex>&)':
/usr/include/boost/thread/pthread/condition_variable.hpp:84: undefined reference to `boost: : this_thread::interruption_point()'
bin/lrelease/libmyProject.a(myProjectBuilder.o): In function `boost:: shared_mutex::lock_shared()':
/usr/include/boost/thread/pthread/shared_mutex.hpp:186: undefined reference to `boost::this_thread::disable_interruption::disable_interruption()'
/usr/include/boost/thread/pthread/shared_mutex.hpp:193: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
/usr/include/boost/thread/pthread/shared_mutex.hpp:193: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
...
...
...
:L/usr/lib
似乎没有任何区别。两者都无法正常工作。
我可以确定代码是正确的,并且可以在其他服务器上正确运行。所以,我真的不知道问题出在哪里。 如果我能获得有关错误的任何有用信息,我将不胜感激,非常感谢:)
答案 0 :(得分:2)
错误消息表明您的libmyProject.a
库依赖于Boost.Thread和Boost.System。但是在链接器命令行中,它在Boost库之后指定,因此未解析其Boost依赖项。请注意,链接器命令行中的库和目标文件的顺序为significant。在您的情况下,您需要在命令行中的库和目标文件之后移动-lboost_thread
和-lboost_system
。