Robomaze
Robomaze

Reputation: 51

How to include boost math library using CMake

I am trying to include the Math library from Boost into my CMake C++ project, however the compiler returns an error when it's linking libraries.

This is my CMakeLists.txt

cmake_minimum_required(VERSION 3.24)
project(ImageProcessor)

set(CMAKE_CXX_STANDARD 17)

find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(ImageProcessor main.cpp)
target_link_libraries(ImageProcessor ${OpenCV_LIBS} Boost::boost)

Edit: This is the error which I get at build:

/usr/bin/ld: CMakeFiles/ImageProcessor.dir/main.cpp.o: undefined reference to symbol '_ZN3tbb6detail2r114execution_slotEPKNS0_2d114execution_dataE'
/usr/bin/ld: /usr/lib/libtbb.so.12: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Upvotes: 3

Views: 1180

Answers (1)

Fabian Keßler
Fabian Keßler

Reputation: 682

Boost is split into multiple CMake targets, Boost::boost is the header only version.

You have to explicitly link to the precompiled components of boost you want to use. In this case, you must also link again Boost::math. It might also be required to search for the component via find_package(Boost REQUIRED COMPONENTS math)

Upvotes: 3

Related Questions