简体   繁体   中英

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

I tried to build this example and got a linkage error:

hekto@ubuntu:~$ g++ -g -Wall -std=c++11 -pthread -DBOOST_LOG_DYN_LINK  -pthread sample.cpp -o sample -lboost_log -lboost_thread -lboost_system
/tmp/cc2EUizv.o: In function `boost::log::v2_mt_posix::basic_formatter<char> boost::log::v2_mt_posix::parse_formatter<char>(char const*)':
/usr/include/boost/log/utility/setup/formatter_parser.hpp:207: undefined reference to `boost::log::v2_mt_posix::basic_formatter<char> boost::log::v2_mt_posix::parse_formatter<char>(char const*, char const*)'
collect2: error: ld returned 1 exit status

How to overcome that?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM