13

I would like to test the Boost.Log library. Unfortunately, I get link errors.

I use Arch Linux, and I installed Boost headers and libraries via built-in package manager pacman:

  • boost 1.54.0-3
  • boost-libs 1.54.0-2

When compiling the simple example from official site via g++ log.cpp -lboost_log -lpthread, I get the following errors:

log.cpp:(.text+0x42): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
log.cpp:(.text+0x9b): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
...

I've read Why my application fails to link with Boost.Log?, but I couldn't solve the link errors. It only gives me the hint that the library where boost::log::v2s_mt_posix::trivial::logger::get() is in was linked statically. But under directory /usr/lib/ there are only dynamically linked Boost libraries with extension .so.

Maybe, someone has a clue what's going wrong here.

Thank you.

Benedikt
  • 205
  • 3
  • 8
  • possible duplicate of [linker error while linking boost log tutorial (undefined references)](http://stackoverflow.com/questions/23137637/linker-error-while-linking-boost-log-tutorial-undefined-references) – Trevor Boyd Smith May 22 '15 at 11:14

2 Answers2

16

You need to define BOOST_LOG_DYN_LINK:

g++ -DBOOST_LOG_DYN_LINK blog.cpp -lboost_log -lpthread
Răzvan Cojocaru
  • 883
  • 9
  • 12
0

If you are using cmake then:

find_package(Boost REQUIRED COMPONENTS system log)
target_link_libraries(credential ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY})

and use:

#define BOOST_LOG_DYN_LINK 1
cakan
  • 2,099
  • 5
  • 32
  • 42