如何使用CMake包含Boost数学库

3
我正在尝试将Boost的Math库包含到我的CMake C ++项目中,但当连接库时编译器返回错误。
这是我的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)

编辑:

这是我在构建时遇到的错误:

/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

你确定需要链接到 boost::math 吗?大多数数学函数都是头文件。你在链接时遇到了什么错误? - Caduchon
我正在尝试使用 math::statistics::simple_ordinary_least_squares_with_R_squared 函数,我已经更新了我的问题,以包括编译错误。 - Robomaze
@Robomaze:如果你只需要数学,可以使用独立的库:https://github.com/boostorg/math/releases/tag/boost-1.80.0 - user14717
1个回答

3
Boost被分成多个CMake目标,Boost::boost是仅包含头文件的版本。
你必须显式地链接到你想使用的预编译组件。在这种情况下,你还必须再次链接 Boost::math。可能还需要通过 find_package(Boost REQUIRED COMPONENTS math) 搜索该组件。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接