我试图建立一个位于HERE的仓库。按照说明,我创建了一个CMakeLists,并更新了其中的目录地址。我不确定OpenCV的路径,但是找到了两个候选者并插入了两个候选者。
Cmake很好,但是在执行make时,出现此错误,我猜可能是由于openCV路径不正确。

这是VERBOSE输出:

[100%] Linking CXX executable SimpleVideoSummExample
/usr/bin/cmake -E cmake_link_script CMakeFiles/SimpleVideoSummExample.dir/link.txt --verbose=1
/usr/bin/c++    -O3 -std=c++0x -std=c++0x -fopenmp  -s CMakeFiles/SimpleVideoSummExample.dir/src/utils/ShotDetector.cc.o CMakeFiles/SimpleVideoSummExample.dir/src/videoSummarization/SimpleVideoSummarizer.cc.o CMakeFiles/SimpleVideoSummExample.dir/src/utils/ColorUtils.cc.o CMakeFiles/SimpleVideoSummExample.dir/src/utils/ImageUtils.cc.o CMakeFiles/SimpleVideoSummExample.dir/examples/SimpleVideoSummExample.cc.o  -o SimpleVideoSummExample  -L/usr/local/Cellar/opencv/3.4.1_2/lib -rdynamic libsummengine.a -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_bgsegm -lopencv_video -lopencv_objdetect -lopencv_dnn -Wl,-rpath,/usr/local/Cellar/opencv/3.4.1_2/lib
/usr/bin/ld: cannot find -lopencv_bgsegm
collect2: error: ld returned 1 exit status
CMakeFiles/SimpleVideoSummExample.dir/build.make:199: recipe for target 'SimpleVideoSummExample' failed
make[2]: *** [SimpleVideoSummExample] Error 1

问题是什么?如何解决?

这是CMakeLists的目录部分(地窖是git repo的用户):
include_directories(/usr/local/Cellar/opencv/3.4.1_2/include/ /usr/local/Cellar/opencv/3.4.1_2/include/opencv/ /usr/include/opencv /usr/local/include/opencv$
link_directories(/usr/local/Cellar/opencv/3.4.1_2/lib/)
add_executable(SimpleVideoSummExample src/utils/ShotDetector.cc src/videoSummarization/SimpleVideoSummarizer.cc src/utils/ColorUtils.cc src/utils/ImageUtils$
target_link_libraries(SimpleVideoSummExample
    summengine -lopencv_imgproc
    -lopencv_core
    -lopencv_highgui
    -lopencv_videoio
    -lopencv_imgcodecs
    -lopencv_bgsegm
    -lopencv_video
    -lopencv_objdetect
    -lopencv_dnn
)

最佳答案

尽管您正在使用的Github存储库没有在文档中明确声明,但您似乎不仅需要OpenCV,而且还需要构建额外的OpenCV modules(由this答案提示)。这些“额外的” OpenCV模块提供了缺少的opencv_bgsegm库。

遵循this之类的教程之后,您应该包括CMake定义标志:
-DOPENCV_EXTRA_MODULES_PATH=/path/to/opencv_contrib/modules/
运行cmake时。这将确保构建额外的模块,并且opencv_bgsegm库将在您的系统上可用。

关于c++ - 使用CMake和Make编译时的OpenCV库错误:找不到-lopencv_bgsegm,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57776568/

10-12 23:50