我试图将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
1条答案
按热度按时间jk9hmnmh1#
Boost被拆分为多个CMake目标,
Boost::boost
是仅标头版本。您必须显式链接到您要使用的boost的预编译组件。在这种情况下,您还必须再次链接
Boost::math
。可能还需要通过find_package(Boost REQUIRED COMPONENTS math)
搜索组件