使用 CMake 构建时对 'cv::cvtColor 的 OpenCV 未定义引用

OpenCV undefined reference to `cv::cvtColor while building with CMake

提问人:TimothyHeadhunter 提问时间:8/28/2023 最后编辑:TsyvarevTimothyHeadhunter 更新时间:8/28/2023 访问量:54

问:

我正在使用 OpenCV 构建一个基本的边缘检测器。我可以用 g++ 编译它,结果也符合预期。但是我需要使用 CMake 构建它,对于下面提到的 CMakeListst.txt,我收到错误:

undefined reference to cv::cvtColor

以及 cv 命名空间中的几乎所有方法。

我的代码编译得很好

g++ -std=c++14 /home/dave/test_edge.cpp -o output `pkg-config opencv4 --cflags --libs`

但是遵循 CMake 会给出错误

CMakeLIsts.txt

cmake_minimum_required(VERSION 2.8.3)

project(Project)

find_package(OpenCV 4 REQUIRED)


include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(output src/EdgeDetector.cpp)
target_include_directories(output PRIVATE include)
target_link_libraries(output ${OpenCV_LIBS})
MESSAGE("OpenCV_LIBS: " ${OpenCV_LIBS} ) 

MESSAGE 输出为:

OpenCV_LIBS: opencv_calib3dopencv_coreopencv_dnnopencv_features2dopencv_flannopencv_gapiopencv_highguiopencv_imgcodecsopencv_imgprocopencv_mlopencv_objdetectopencv_photoopencv_stitchingopencv_videoopencv_videoio

我知道问题出在链接上,但我已经达到了饱和点。我对 CMake 有点陌生,仍在学习,任何帮助都不胜感激。

C++ opencv cmake linker undefined-reference

评论


答: 暂无答案