Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include boost math library using CMake

Tags:

c++

boost

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
like image 203
Robomaze Avatar asked Oct 17 '25 13:10

Robomaze


1 Answers

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)

like image 143
Fabian Keßler Avatar answered Oct 20 '25 03:10

Fabian Keßler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!