项目场景:
OpenCV VScode MingW配置
问题描述
使用MingW编译时出现bug:
[build] C:/opencvild/include/opencv2/core/utility.hpp:719:14: error: 'recursive_mutex' in namespace 'std' does not name a type
[build] typedef std::recursive_mutex Mutex;
[build] ^~~~~~~~~~~~~~~
[build] C:/opencvild/include/opencv2/core/utility.hpp:719:9: note: 'std::recursive_mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
[build] C:/opencvild/include/opencv2/core/utility.hpp:61:1:
原因分析:
从官网下载的OpenCV 库是支持MSVS 编译的
使用Visual Sudto Communiny 2022 Rlae x86 amd64编译没问题,其为Visual Studio 2022环境包,
但是不支持mingw64
解决方案:
需要进行make编译为支持mingw64的,或者直接下载编译好的OpenCV
下面附上链接:
https://github.com/huihut/OpenCV-MinGW-Build/tree/OpenCV-4.5.5-x64/x64/mingw/lib
随后更改CMakeLists.txt,进行库链接
附上代码
cmake_minimum_required(VERSION 3.10)
project(test1vb)
# 指定 OpenCV 的根目录(使用 MinGW 编译的 OpenCV)
set(OpenCV_DIR "D:\\opencv\\x64\\mingw\\lib")
# 查找 OpenCV
find_package(OpenCV REQUIRED)
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV not found!")
endif()
# 添加头文件路径
include_directories(${
OpenCV_INCLUDE_DIRS})
# include_directories("${PYLON_DIR}/include")
# 创建可执行文件
add_executable(${
PROJECT_NAME} src/Main.cpp)
# 链接 OpenCV 库
target_link_libraries(${
PROJECT_NAME} ${
OpenCV_LIBS})