提问人:newInCPlusPlus 提问时间:3/9/2022 最后编辑:newInCPlusPlus 更新时间:3/9/2022 访问量:173
CLion 和 CMake 没有抱怨,但无法构建 OpenCV
CLion and CMake Doesn't Complain but Failed to build OpenCV
问:
总结
在 Windows 中,CLion 在 cmake 之后和 makefile 之前不会抱怨任何内容。
- 所有代码似乎都正确链接,没有错误。我能够看到参考文献、文档、linter 并使用 .
cv::Mat
opencv.hpp
ctrl
RMB
- CMake 似乎正确生成了 make 文件,没有错误。
但是编译错误发生:OpenCV 方法。undefined reference to
我的设置
CMakeLists.txt
:
cmake_minimum_required(VERSION 3.9)
project(test)
# Set compile version
set(CMAKE_CXX_STANDARD 17)
add_executable(test ./test.cpp )
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " libraries: ${OpenCV_LIBRARIES}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
target_link_libraries(test ${OpenCV_LIBRARIES})
输出似乎是正确的
"D:\Program Files\JetBrains\CLion 2021.3.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\repo\CS5330\test
-- OpenCV library status:
-- version: 4.5.5
-- libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_world
-- libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_world
-- include path: /path/to/scoop/apps/opencv/current/include
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/test/cmake-build-debug
[Finished]
这会产生 ,其中包括,CMakeCache.txt
//The directory containing a CMake configuration file for OpenCV.
OpenCV_DIR:PATH= /path/to/scoop/apps/opencv/current/x64/vc15/lib
//Details about finding OpenCV
FIND_PACKAGE_MESSAGE_DETAILS_OpenCV:INTERNAL=[/path/to/scoop/apps/opencv/current][v4.5.5()]
如您所见,CLion 已经设置并正确读取了系统范围的环境变量。OpenCV_DIR
这是一个简单的测试代码,但运行失败
#include <opencv2/opencv.hpp>
int main() {
cv::Mat img = cv::imread("./test.jpg", -1);
cv::imshow("Mon image", img);
cv::waitKey(0);
return 0;
}
我还安装了 from 和 from installed , , ,。按照本教程进行操作。
通过该工具链而不是 CLion 捆绑工具链进行测试,它返回相同的结果。msys2
winget
msys2
clang
make
MinGW-w64 GDB
cmake
OpenCV
binary 来自 。scoop
出于某种原因,它与自制软件存在相同的问题。在 中,由于 opencv.hpp 位于 opencv2 文件夹中的文件层次结构,包含标头不正确。
我把所有都改成了,但它没有帮助,反之亦然。opencv.hpp
#include "opencv2/header.hpp"
#include "header.hpp"
几个小时都搞不清原因..任何帮助将不胜感激。
答: 暂无答案
评论
x64/vc15/lib