Boost.Log failing to link with static libraries be

2019-06-01 16:36发布

I'm trying to link Boost.Log statically into my program. Boost.Log has successfully compiled with other modules using bjam. However, when I try to link with my program I'm getting an error:

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

I've compiled boost with the following:

./b2 --ignore-site-config -a -j9 --with-timer --with-system --with-chrono --with-iostreams --with-log --with-thread variant=debug link=static threading=multi

So far:

  1. I've tried to troubleshoot it using this article (http://www.boost.org/doc/libs/1_60_0/libs/log/doc/html/log/rationale/namespace_mangling.html) that talks about how it could be a different namespace based on compiling. However, when I look in the libboost_log.a I can see functions named like so "void boost::log::v2s_mt_posix::aux::code_convert
  2. This article (https://sourceforge.net/p/boost-log/discussion/710022/thread/2a7b5c0d/) says to make sure both BOOST_LOG_USE_CHAR and BOOST_LOG_USE_WCHAR_T are not defined. They are not.
  3. Other articles say to define BOOST_LOG_DYN_LINK,but I'm using static libraries.

Here is how it's defined in my 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

How can I nix this linker error?

1条回答
Juvenile、少年°
2楼-- · 2019-06-01 17:20

You're likely including headers from an older version of Boost.

In 1.60, the code_convert series of functions are templated, but the error you're seeing is an undefined reference to a non-templated function.

查看更多
登录 后发表回答