我正在尝试将Boost.Log静态链接到我的程序中。 Boost.Log已使用bjam与其他模块成功编译。但是,当我尝试链接到我的程序时,我收到了一个错误:
g++ -g -O2 -pthread -o sonar sonar-main.o sonar-config.o sonar-util.o sonar-logger.o /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_system.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_timer.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_iostreams.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_thread.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_log_setup.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_log.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_filesystem.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_atomic.a -lcrypto -lssl
sonar-logger.o: In function `void boost::log::v2s_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >::aligned_write<wchar_t>(wchar_t const*, long)':
/usr/include/boost/log/utility/formatting_ostream.hpp:702: undefined reference to `boost::log::v2s_mt_posix::aux::code_convert(wchar_t const*, unsigned long, std::string&, std::locale const&)'
/usr/include/boost/log/utility/formatting_ostream.hpp:696: undefined reference to `boost::log::v2s_mt_posix::aux::code_convert(wchar_t const*, unsigned long, std::string&, std::locale const&)'
sonar-logger.o: In function `void boost::log::v2s_mt_posix::type_dispatcher::callback_base::trampoline<boost::log::v2s_mt_posix::binder1st<boost::log::v2s_mt_posix::output_fun, boost::log::v2s_mt_posix::expressions::aux::stream_ref<boost::log::v2s_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> > >&>, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >(void*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)':
/usr/include/boost/log/utility/formatting_ostream.hpp:575: undefined reference to `boost::log::v2s_mt_posix::aux::code_convert(wchar_t const*, unsigned long, std::string&, std::locale const&)'
collect2: error: ld returned 1 exit status
我使用以下内容编译了boost:
./b2 --ignore-site-config -a -j9 --with-timer --with-system --with-chrono --with-iostreams --with-log --with-thread variant=debug link=static threading=multi
到目前为止:
以下是我在Makefile.am中的定义:
sonar_CPPFLAGS = -march=native -pipe -funroll-loops -fomit-frame-pointer -fforce-addr -fprefetch-loop-arrays -Wall -std=c++0x
sonar_SOURCES = main.cpp \
config.cpp \
config.hpp \
util.cpp \
util.hpp \
logger.cpp \
logger.hpp
sonar_LDADD = /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_system.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_timer.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_iostreams.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_thread.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_log_setup.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_log.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_filesystem.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_atomic.a -lcrypto -lssl
sonar_LDFLAGS = -pthread
如何解决此链接器错误?
答案 0 :(得分:2)
您可能会包含旧版Boost的标题。
在1.60中,code_convert
系列函数是模板化的,但您看到的错误是对未模板化函数的未定义引用。