CMake第三方依赖项无法编译OpenCV,无法找到确实存在的文件

时间:2019-06-12 08:00:47

标签: cmake

我正在将cake项目用于移动应用程序中的c ++项目,因此我需要将所有第三方代码放入源代码树的文件夹中,如下所示:

./ third_party / opencv /(<-此仓库的内容在https://github.com/opencv/opencv中)

其余的应用程序代码位于./

我有一个主要工作的CMakeLists.txt,它开始处理opencv代码:

[ 35%] Building CXX object third_party/opencv/modules/calib3d/CMakeFiles/opencv_calib3d.dir/src/undistort.cpp.o
[ 35%] Building CXX object third_party/opencv/modules/calib3d/CMakeFiles/opencv_calib3d.dir/src/upnp.cpp.o
[ 35%] Building CXX object third_party/opencv/modules/calib3d/CMakeFiles/opencv_calib3d.dir/opencl_kernels_calib3d.cpp.o
[ 35%] Building CXX object third_party/opencv/modules/calib3d/CMakeFiles/opencv_calib3d.dir/src/undistort.avx2.cpp.o

无论如何,opencv找不到该第三方目录中的文件:

[ 36%] Linking CXX shared library ../../lib/libopencv_calib3d.so
[ 36%] Built target opencv_calib3d
Scanning dependencies of target run_tests
[ 36%] Building CXX object CMakeFiles/run_tests.dir/tests/tests.cpp.o
In file included from /root/repo/third_party/opencv/modules/core/include/opencv2/core.hpp:54,
                 from /root/repo/third_party/opencv/modules/imgproc/include/opencv2/imgproc.hpp:46,
                 from /root/repo/tests/../third_party/opencv/modules/imgproc/include/opencv2/imgproc/imgproc.hpp:48,
                 from /root/repo/tests/tests.cpp:7:
/root/repo/third_party/opencv/modules/core/include/opencv2/core/base.hpp:52:10: fatal error: opencv2/opencv_modules.hpp: No such file or directory
 #include "opencv2/opencv_modules.hpp"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/run_tests.dir/build.make:62: recipe for target 'CMakeFiles/run_tests.dir/tests/tests.cpp.o' failed
make[2]: *** [CMakeFiles/run_tests.dir/tests/tests.cpp.o] Error 1
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/run_tests.dir/all' failed
make[1]: *** [CMakeFiles/run_tests.dir/all] Error 2

错误中提到的./tests/tests.cpp具有以下内容:

#include <string>
#include <iostream>
#include <stdio.h>
#include <unordered_set>
#include <vector>
#include <gtest/gtest.h>
#include "../third_party/opencv/modules/imgproc/include/opencv2/imgproc/imgproc.hpp"
#include "../third_party/opencv/modules/highgui/include/opencv2/highgui.hpp"
#include "../third_party/opencv/modules/videoio/include/opencv2/videoio.hpp"
#include "../video_processing.hpp"
#include "../hashing.hpp"
#include "../utils.hpp"

我确实看到它抱怨的opencv_modules.hpp实际上不存在,但是这个文件确实https://github.com/opencv/opencv/blob/master/cmake/templates/opencv_modules.hpp.in

但是我是C ++和CMake的新手,所以我不知道这是什么,也不知道如何从中创建hpp文件。

这是我的CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
project(root)

find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
    set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)

find_package(ZXing CONFIG)

# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

add_subdirectory(third_party)

add_executable(application ${PROJECT_SOURCE_DIR}/main.cpp)
add_executable(run_tests ${PROJECT_SOURCE_DIR}/tests/tests.cpp)

set(LINK_LIBS ${GTEST_LIBRARIES} pthread ${ZBAR_LIBRARIES} ZXingCore opencv_core opencv_imgcodecs opencv_imgproc opencv_features2d opencv_calib3d opencv_videoio)
target_link_libraries(application ${LINK_LIBS})
target_link_libraries(run_tests ${LINK_LIBS})

file(GLOB OPENCV_MODULE_INCLUDE_DIRS third_party/opencv/include third_party/opencv/modules/*/include )

target_include_directories(application PUBLIC ${OPENCV_MODULE_INCLUDE_DIRS})
target_include_directories(run_tests PUBLIC ${OPENCV_MODULE_INCLUDE_DIRS})

有人能在CMakeLists.txt中发现问题,导致OpenCV包含其自己的文件失败吗?

0 个答案:

没有答案