由于缺少code_convert,Boost.Log无法与静态库链接

时间:2016-03-07 19:35:50

标签: c++ boost static-libraries linker-errors boost-log

我正在尝试将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

到目前为止:

  1. 我尝试使用本文(http://www.boost.org/doc/libs/1_60_0/libs/log/doc/html/log/rationale/namespace_mangling.html)对其进行故障排除,该文章讨论了如何基于编译将其命名为不同的命名空间。但是,当我查看libboost_log.a时,我可以看到如此命名的函数“void boost :: log :: v2s_mt_posix :: aux :: code_convert
  2. 本文(https://sourceforge.net/p/boost-log/discussion/710022/thread/2a7b5c0d/)表示要确保未定义BOOST_LOG_USE_CHAR和BOOST_LOG_USE_WCHAR_T。他们不是。
  3. 其他文章说要定义BOOST_LOG_DYN_LINK,但我正在使用静态库。
  4. 以下是我在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
    

    如何解决此链接器错误?

1 个答案:

答案 0 :(得分:2)

您可能会包含旧版Boost的标题。

在1.60中,code_convert系列函数是模板化的,但您看到的错误是对未模板化函数的未定义引用。