cmake 找到自定义 OpenCV,忽略它

cmake finds custom OpenCV, ignores it

我在我的系统上构建了 OpenCV 3,因为我的包管理器没有提供它,但 cmake 仍然使用系统版本。

不出所料,当我将 OpenCV_DIR 留空时,以下操作失败(因为系统 OpenCV 是 2.4)

FIND_PACKAGE(OpenCV 3 REQUIRED)

当我 export OPENCV_DIR=/home/fruitcake/Desktop/opencvsrc/installed 检查通过时,但是变量被设置到系统 OpenCV 目录导致编译时错误。

例如:OPENCV_CFLAGS应该设置为前缀目录。

我假设 /OpenCVModules-release.cmake 中发生了一些神奇的事情,但我不知道 OPENCV_CFLAGS 是如何设置的。

拥有自定义 OpenCV 搜索目录的典型方法是什么 OPENCV_CFLAGS

-- CONFIG_FILES=/home/fruitcake/Desktop/opencvsrc/installed/share/OpenCV/OpenCVModules-release.cmake
-- OPENCV_CFLAGS=-I/usr/include/opencv
-- OPENCV_INCLUDE_DIRS=/usr/include/opencv
-- OPENCV_LDFLAGS=/usr/lib64/libopencv_calib3d.so;/usr/lib64/libopencv_contrib.so;/usr/lib64/libopencv_core.so;/usr/lib64/libopencv_features2d.so;/usr/lib64/libopencv_flann.so;/usr/lib64/libopencv_gpu.so;/usr/lib64/libopencv_highgui.so;/usr/lib64/libopencv_imgproc.so;/usr/lib64/libopencv_legacy.so;/usr/lib64/libopencv_ml.so;/usr/lib64/libopencv_nonfree.so;/usr/lib64/libopencv_objdetect.so;/usr/lib64/libopencv_photo.so;/usr/lib64/libopencv_stitching.so;/usr/lib64/libopencv_superres.so;/usr/lib64/libopencv_ts.a;/usr/lib64/libopencv_video.so;/usr/lib64/libopencv_videostab.so;/usr/lib64/libXext.so;/usr/lib64/libX11.so;/usr/lib64/libICE.so;/usr/lib64/libSM.so;/usr/lib64/libGL.so;/usr/lib64/libGLU.so;-lrt;-lpthread;-lm;-ldl
-- OPENCV_LDFLAGS_OTHER=/usr/lib64/libopencv_calib3d.so;/usr/lib64/libopencv_contrib.so;/usr/lib64/libopencv_core.so;/usr/lib64/libopencv_features2d.so;/usr/lib64/libopencv_flann.so;/usr/lib64/libopencv_gpu.so;/usr/lib64/libopenc _highgui.so;/usr/lib64/libopencv_imgproc.so;/usr/lib64/libopencv_legacy.so;/usr/lib64/libopencv_ml.so;/usr/lib64/libopencv_nonfree.so;/usr/lib64/libopencv_objdetect.so;/usr/lib64/libopencv_photo.so;/usr/lib64/libopencv_stitching.so;/usr/lib64/libopencv_superres.so;/usr/lib64/libopencv_ts.a;/usr/lib64/libopencv_video.so;/usr/lib64/libopencv_videostab.so;/usr/lib64/libXext.so;/usr/lib64/libX11.so;/usr/lib64/libICE.so;/usr/lib64/libSM.so;/usr/lib64/libGL.so;/usr/lib64/libGLU.so
-- OPENCV_STATIC_CFLAGS=-I/usr/include/opencv
-- OPENCV_STATIC_INCLUDE_DIRS=/usr/include/opencv
-- OPENCV_STATIC_LDFLAGS=/usr/lib64/libopencv_calib3d.so;/usr/lib64/libopencv_contrib.so;/usr/lib64/libopencv_core.so;/usr/lib64/libopencv_features2d.so;/usr/lib64/libopencv_flann.so;/usr/lib64/libopencv_gpu.so;/usr/lib64/libopencv_highgui.so;/usr/lib64/libopencv_imgproc.so;/usr/lib64/libopencv_legacy.so;/usr/lib64/libopencv_ml.so;/usr/lib64/libopencv_nonfree.so;/usr/lib64/libopencv_objdetect.so;/usr/lib64/libopencv_photo.so;/usr/lib64/libopencv_stitching.so;/usr/lib64/libopencv_superres.so;/usr/lib64/libopencv_ts.a;/usr/lib64/libopencv_video.so;/usr/lib64/libopencv_videostab.so;/usr/lib64/libXext.so;/usr/lib64/libX11.so;/usr/lib64/libICE.so;/usr/lib64/libSM.so;/usr/lib64/libGL.so;/usr/lib64/libGLU.so;-lrt;-lpthread;-lm;-ldl
-- OPENCV_STATIC_LDFLAGS_OTHER=/usr/lib64/libopencv_calib3d.so;/usr/lib64/libopencv_contrib.so;/usr/lib64/libopencv_core.so;/usr/lib64/libopencv_features2d.so;/usr/lib64/libopencv_flann.so;/usr/lib64/libopencv_gpu.so;/usr/lib64/libopencv_highgui.so;/usr/lib64/libopencv_imgproc.so;/usr/lib64/libopencv_legacy.so;/usr/lib64/libopencv_ml.so;/usr/lib64/libopencv_nonfree.so;/usr/lib64/libopencv_objdetect.so;/usr/lib64/libopencv_photo.so;/usr/lib64/libopencv_stitching.so;/usr/lib64/libopencv_superres.so;/usr/lib64/libopencv_ts.a;/usr/lib64/libopencv_video.so;/usr/lib64/libopencv_videostab.so;/usr/lib64/libXext.so;/usr/lib64/libX11.so;/usr/lib64/libICE.so;/usr/lib64/libSM.so;/usr/lib64/libGL.so;/usr/lib64/libGLU.so
-- OPENCV_opencv_INCLUDEDIR=
-- OPENCV_opencv_LIBDIR=
-- OPENCV_opencv_PREFIX=
-- OPENCV_opencv_VERSION=
-- OpenCV_CONFIG=/home/fruitcake/Desktop/opencvsrc/installed/share/OpenCV/OpenCVConfig.cmake
-- OpenCV_CONSIDERED_CONFIGS=/home/fruitcake/Desktop/opencvsrc/installed/share/OpenCV/OpenCVConfig.cmake
-- OpenCV_DIR=/home/fruitcake/Desktop/opencvsrc/installed/share/OpenCV
-- OpenCV_FIND_COMPONENTS_=opencv_videostab;opencv_videoio;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_shape;opencv_photo;opencv_objdetect;opencv_ml;opencv_imgproc;opencv_imgcodecs;opencv_highgui;opencv_flann;opencv_features2d;opencv_cudev;opencv_cudawarping;opencv_cudastereo;opencv_cudaoptflow;opencv_cudalegacy;opencv_cudaimgproc;opencv_cudafilters;opencv_cudafeatures2d;opencv_cudacodec;opencv_cudabgsegm;opencv_cudaarithm;opencv_cuda;opencv_core;opencv_calib3d
-- OpenCV_INCLUDE_DIRS=/usr/include/opencv;/usr/include
-- OpenCV_LIBRARIES=opencv_videostab;opencv_videoio;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_shape;opencv_photo;opencv_objdetect;opencv_ml;opencv_imgproc;opencv_imgcodecs;opencv_highgui;opencv_flann;opencv_features2d;opencv_cudev;opencv_cudawarping;opencv_cudastereo;opencv_cudaoptflow;opencv_cudalegacy;opencv_cudaimgproc;opencv_cudafilters;opencv_cudafeatures2d;opencv_cudacodec;opencv_cudabgsegm;opencv_cudaarithm;opencv_cuda;opencv_core;opencv_calib3d
-- OpenCV_LIBS=opencv_videostab;opencv_videoio;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_shape;opencv_photo;opencv_objdetect;opencv_ml;opencv_imgproc;opencv_imgcodecs;opencv_highgui;opencv_flann;opencv_features2d;opencv_cudev;opencv_cudawarping;opencv_cudastereo;opencv_cudaoptflow;opencv_cudalegacy;opencv_cudaimgproc;opencv_cudafilters;opencv_cudafeatures2d;opencv_cudacodec;opencv_cudabgsegm;opencv_cudaarithm;opencv_cuda;opencv_core;opencv_calib3d
-- OpenCV_LIBS_DBG=opencv_videostab;opencv_videoio;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_shape;opencv_photo;opencv_objdetect;opencv_ml;opencv_imgproc;opencv_imgcodecs;opencv_highgui;opencv_flann;opencv_features2d;opencv_cudev;opencv_cudawarping;opencv_cudastereo;opencv_cudaoptflow;opencv_cudalegacy;opencv_cudaimgproc;opencv_cudafilters;opencv_cudafeatures2d;opencv_cudacodec;opencv_cudabgsegm;opencv_cudaarithm;opencv_cuda;opencv_core;opencv_calib3d
-- OpenCV_LIBS_OPT=opencv_videostab;opencv_videoio;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_shape;opencv_photo;opencv_objdetect;opencv_ml;opencv_imgproc;opencv_imgcodecs;opencv_highgui;opencv_flann;opencv_features2d;opencv_cudev;opencv_cudawarping;opencv_cudastereo;opencv_cudaoptflow;opencv_cudalegacy;opencv_cudaimgproc;opencv_cudafilters;opencv_cudafeatures2d;opencv_cudacodec;opencv_cudabgsegm;opencv_cudaarithm;opencv_cuda;opencv_core;opencv_calib3d
-- OpenCV_LIB_COMPONENTS=opencv_videostab;opencv_videoio;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_shape;opencv_photo;opencv_objdetect;opencv_ml;opencv_imgproc;opencv_imgcodecs;opencv_highgui;opencv_flann;opencv_features2d;opencv_cudev;opencv_cudawarping;opencv_cudastereo;opencv_cudaoptflow;opencv_cudalegacy;opencv_cudaimgproc;opencv_cudafilters;opencv_cudafeatures2d;opencv_cudacodec;opencv_cudabgsegm;opencv_cudaarithm;opencv_cuda;opencv_core;opencv_calib3d
-- _DIR=/home/fruitcake/Desktop/opencvsrc/installed/share/OpenCV
-- OPENCV_DIR: /usr/include/opencv

我正在使用 cmake 版本 3.1.0

我不得不删除 CMakeCache.txt