2

Using cmake I am not able to use boost::log

I still get this error undefined reference to:

boost::log::v2_mt_posix::trivial::logger::get()

I am using boost 1.71. I have this working like:

- g++ ../log_example.cpp -DBOOST_LOG_DYN_LINK -lpthread -lboost_log -o log_example

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

linking boost log using cmake error

However, With cmake I have try several different options mention before. Not a single one has works for cmake.

The cmake is as follows

cmake_minimum_required(VERSION 3.10)
project(log_example)
set(CMAKE_CXX_STANDARD 17)
set(Boost_USE_DEBUG_LIBS         OFF) # ignore debug libs and
set(Boost_USE_RELEASE_LIBS       ON)  # only find release libs
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
set(CMAKE_CXX_COMPILER "g++")
ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
find_package(Boost 1.70.0 COMPONENTS thread log REQUIRED log_setup)
include_directories(${BOOST_INCLUDE_DIRS})
add_executable(log_example log_example.cpp)
target_link_libraries(log_example pthread ${Boost_LIBRARIES} ${Boost_LOG_LIBRARY} )
set(CMAKE_CXX_FLAGS "-g -Wall -DBOOST_LOG_DYN_LINK")
Santiwake
  • 79
  • 7
  • Note that use of the variables like `${Boost_LOG_LIBRARY}` is obsolete, [the documentation](https://cmake.org/cmake/help/latest/module/FindBoost.html) recommends to use the targets like `Boost::log` instead. – Some programmer dude Sep 09 '19 at 14:25
  • 1
    As for your problem, you need to link with the Boost log setup library as well (target `Boost::log_setup`), not only look for it. – Some programmer dude Sep 09 '19 at 14:28

1 Answers1

1

solved Awesome thanks every one. The cmake now looks like this and works perfectly, less clutter and to the point.

cmake_minimum_required(VERSION 3.10)
project(log_example)
set(CMAKE_CXX_STANDARD 17)
find_package(Boost 1.70.0 COMPONENTS thread log log_setup)
include_directories(${BOOST_INCLUDE_DIRS})
add_executable(log_example log_example.cpp)
target_link_libraries(log_example pthread Boost::log Boost::log_setup )
Santiwake
  • 79
  • 7