Linker Error While Linking Boost Log Tutorial (Undefined References)

linker error while linking boost log tutorial (undefined references)

Just add a line

#define BOOST_LOG_DYN_LINK 1

as the first line of boosttest.cc.

Alternatively, you can add -DBOOST_LOG_DYN_LINK to you compilation step (not the linking step, as you posted in the question):

g++ -std=c++11 -Wall -pedantic -g -O0 -DBOOST_LOG_DYN_LINK  -c boosttest.cc
g++ boosttest.o -lpthread -lboost_log -o boosttest

linker error while linking boost log (undefined references to boost::log::v2_mt_posix::sinks)

After some digging, I found a clue:
Sample Image
It looks like some files are left even after uninstalling of previous boost version 1.58 in /usr/lib/x86_64-linux-gnu

The issue was resolved after I deleted manually all libboost* files with exception for *.so.1.58.0 (see description below why) from /usr/lib/x86_64-linux-gnu left from the previous installation (my currently installed boost v 1.64 is in /usr/local):
Sample Image

Be aware that deleting of *. so. 1.58.0 files can make some apps not working (Firefox and chrome in my case), so I had to build boost v 1.58 and place them back to make them operational again

Linkage error with Boost Log 1.65.0 example from the Boost.org

I'm answering my own question, following the @Praetorian help and suggestion.

The Boost Log relies on two libraries (I thought it was only one):

hekto@ubuntu:~$ ls -l /usr/lib/x86_64-linux-gnu/libboost_log*
-rw-r--r-- 1 root root 3510082 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log.a
-rw-r--r-- 1 root root 2441460 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log_setup.a
lrwxrwxrwx 1 root root 28 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log_setup.so -> libboost_log_setup.so.1.65.1
-rw-r--r-- 1 root root 671944 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log_setup.so.1.65.1
lrwxrwxrwx 1 root root 22 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log.so -> libboost_log.so.1.65.1
-rw-r--r-- 1 root root 905752 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log.so.1.65.1

If you compile and link on Linux, you'll have to provide a list of Boost libraries on the command line. According to an answer to this question, given by the main developer (@AndreySemashev) of the Boost Log, these libraries on the command line should look like this:

-lboost_log_setup -lboost_log

Probably it makes sense to provide two libraries instead of one (for example, when you link statically), but I couldn't find any recommendations about when we should use a single library, and when - both of them.

Boost.Log linking errors under GNU/Linux

You need to define BOOST_LOG_DYN_LINK:

g++ -DBOOST_LOG_DYN_LINK blog.cpp -lboost_log -lpthread

Boost.Log with CMake causing undefined reference error

It looks like it boils down to linking to the shared version of Boost.Log.

There is a bit of detail on the issue in the docs for Boost.Log Your error message mentions the namespace boost::log::v2s_mt_posix and from the docs, this implies the linker is expecting to link to a static version of Boost.Log.

If you want to link to the shared version, it seems you need to define BOOST_LOG_DYN_LINK or BOOST_ALL_DYN_LINK, i.e. in your CMakeLists.txt add:

ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)

If you want to link to the static version of Boost.Log, instead you need to add a CMake variable before calling FIND_PACKAGE(Boost ...):

SET(Boost_USE_STATIC_LIBS ON)
FIND_PACKAGE(Boost 1.54 COMPONENTS log REQUIRED)

For further variables which affect how CMake finds Boost, see the docs for FindBoost.

Boost.Log linker error when using init_from_source

The missing symbols are from Boost.Regex, which is used by Boost.Log (more precisely, boost_log_setup references its symbols internally). You need to add Boost.Regex to the list of the libraries to link with. Given your error messages, that should be libboost_regex-vc141-mt-gd-x64-1_69.lib for your static linking build.

linking boost log using cmake error

Just try to add this line

#define BOOST_LOG_DYN_LINK 1

As the first line of the main.cpp file, i think it should work, someone got your same issue here

If that doesn't work, try to add this line

ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)

To CMake file
You need to add OpenMP package too



Related Topics



Leave a reply



Submit