I am aware this question was asked many times before, always ending with the same answer... add -DBOOST_LOG_DYN_LINK
to your CMakeLists.txt
file.
However, I've had this in my cmake for a long time and everything was linking without any problems. Now I decided to switch to Ubuntu 18.04 from 16.04 and update my projects one by one....
This is my cmake file:
cmake_minimum_required(VERSION 2.8.4)
project(FOO)
find_package(Boost REQUIRED COMPONENTS system timer filesystem log program_options unit_test_framework)
find_package(CGAL COMPONENTS Core)
find_library(OPEN_MESH_CORE_LIBRARY OpenMeshCore /usr/local/lib/OpenMesh REQUIRED)
find_library(YAML_CPP_LIBRARY yaml-cpp REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONCPP jsoncpp)
link_libraries(${JSONCPP_LIBRARIES})
include_directories(${JSONCPP_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -fopenmp -msse2 -march=native -W -Wall -std=c++11")
add_definitions(-DBOOST_LOG_DYN_LINK=1)
add_definitions(-DUNIT_TEST_DATA="${CMAKE_SOURCE_DIR}/data")
include( ${CGAL_USE_FILE} )
include( CGAL_CreateSingleSourceCGALProgram )
set(SOURCE_FILES
Foo1.cpp
Foo2.cpp
Foo3.cpp)
add_executable(FOO main.cpp ${SOURCE_FILES})
target_include_directories(FOO PRIVATE ${JsonCpp_INCLUDE_DIRS})
target_link_libraries(FOO ${OPEN_MESH_CORE_LIBRARY} ${Boost_LIBRARIES} ${YAML_CPP_LIBRARY} ${JSONCPP_LIBRARIES})
add_library(foo SHARED ${SOURCE_FILES})
target_link_libraries(foo ${OPEN_MESH_CORE_LIBRARY} ${Boost_LIBRARIES} ${YAML_CPP_LIBRARY} ${JSONCPP_LIBRARIES})
add_executable(tests test.cpp ${SOURCE_FILES})
target_include_directories(FOO PRIVATE ${JsonCpp_INCLUDE_DIRS})
target_link_libraries(tests ${OPEN_MESH_CORE_LIBRARY} ${Boost_LIBRARIES} ${YAML_CPP_LIBRARY} ${JSONCPP_LIBRARIES})
When compiled, it fails with known long list of problems, all related ending with a message
undefined reference to boost::log::v2_mt_posix::...
I am not a cmake ninja and it is very likely that I am doing something wrong, however, I can not find out what it is.
EDIT:
- I have successfully tried to build it on a clean Ubuntu 16.04 with gcc 5 and boost 1.58
- I have unsuccessfully tried to build it on a clean 18.04 with gcc7.1 and boost 1.65
- I have unsuccessfully tried to build it on a clean 18.04 with gcc 5.5 and self compiled boost 1.58
- I have unsuccessfully tried to build it on a clean 18.04 with gcc 5.5 and self compiled boost 1.65
All attempts followed an exactly the same procedure.