Mingw32编译opencv库

文章目录

  • 1. 准备工作
  • 2. 编译
    • cmake构建程序
    • mingw32-make编译
  • 3. 安装
  • 4. 安装完的结果

注意:
mingw32-make编译的库和MSVC编译的库不兼容,MSVC和mingw-make生成的动态库使用的是不同的ABI(Application Binary Interface),不能混合使用由这两个编译器生成的库。例如,如果你的程序使用了由MSVC编译的库,那么你的程序也必须使用MSVC来编译。另外mingw32-make编译的库的库文件是.a后缀,MSVC编译的库的库文件是.lib。

1. 准备工作

  • 安装cmake
    参考

  • 安装mingw32
    参考

  • 下载opencv源码
    下载地址:https://codeload.github.com/opencv/opencv/zip/refs/tags/4.6.0
    下载后解压。

2. 编译

cmake构建程序

  • 进入opencv源码目录
  • 新建build目录
  • 进入build目录
  • 执行cmake命令
D:\myApp\opencv460\opencv-4.6.0>mkdir buildD:\myApp\opencv460\opencv-4.6.0>cd buildD:\myApp\opencv460\opencv-4.6.0\build>cmake .. -G "MinGW Makefiles" -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=D:\myApp\opencv460\opencv-4.6.0\build -D BUILD_opencv_world=ON
-- The CXX compiler identification is GNU 13.2.0
-- The C compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/myApp/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/myApp/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- ocv_init_download: OpenCV source tree is not fetched as git repository. 3rdparty resources will be downloaded from github.com by default.
-- Detected processor: AMD64
CMake Warning (dev) at cmake/OpenCVUtils.cmake:144 (find_package):Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modulesare removed.  Run "cmake --help-policy CMP0148" for policy details.  Usethe cmake_policy command to set the policy and suppress this warning.Call Stack (most recent call first):cmake/OpenCVDetectPython.cmake:64 (find_host_package)cmake/OpenCVDetectPython.cmake:271 (find_python)CMakeLists.txt:628 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.-- Found PythonInterp: D:/myApp/anaconda3/python.exe (found suitable version "3.11.5", minimum required is "2.7")
CMake Warning at cmake/OpenCVDetectPython.cmake:81 (message):CMake's 'find_host_package(PythonInterp 2.7)' found wrong Python version:PYTHON_EXECUTABLE=D:/myApp/anaconda3/python.exePYTHON_VERSION_STRING=3.11.5Consider providing the 'PYTHON2_EXECUTABLE' variable via CMake command lineor environment variablesCall Stack (most recent call first):cmake/OpenCVDetectPython.cmake:271 (find_python)CMakeLists.txt:628 (include)。。。。。。。。。。。。。。。。。。。。

上面关键的指令是这一句:

cmake .. -G "MinGW Makefiles" -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=D:\myApp\opencv460\opencv-4.6.0\build -D BUILD_opencv_world=ON

解释一下:

  • … 表示上一级目录,即opencv源码目录
  • -G “MinGW Makefiles” 表示生成MinGW Makefiles工程
  • -D CMAKE_BUILD_TYPE=RELEASE 表示编译类型为RELEASE
  • -D CMAKE_INSTALL_PREFIX=D:\myApp\opencv460\opencv-4.6.0\build 表示安装目录
  • -D BUILD_opencv_world=ON 表示编译opencv_world库

mingw32-make编译

  • 执行mingw32-make命令
mingw32-make -j8

输出如下:

D:\myApp\opencv460\opencv-4.6.0\build>mingw32-make -j 8
[  0%] Built target opencv_videoio_plugins
[  0%] Building C object 3rdparty/openjpeg/openjp2/CMakeFiles/libopenjp2.dir/thread.c.obj
[  0%] Built target opencv_highgui_plugins
[  0%] Building CXX object CMakeFiles/ade.dir/3rdparty/ade/ade-0.1.1f/sources/ade/source/alloc.cpp.obj
[  0%] Building C object 3rdparty/quirc/CMakeFiles/quirc.dir/src/decode.c.obj
[  0%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/adler32.c.obj
[  0%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcapimin.c.obj
[  0%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/dec/alpha_dec.c.obj
[  0%] Building C object 3rdparty/openjpeg/openjp2/CMakeFiles/libopenjp2.dir/bio.c.obj
[  0%] Building C object 3rdparty/quirc/CMakeFiles/quirc.dir/src/quirc.c.obj

note: -j8 表示8个线程编译,可以根据自己的电脑配置来设置。
如果报错如下

D:/myApp/opencv460/opencv-4.6.0/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:101:10: error:
'uintptr_t' in namespace 'std' does not name a type101 |     std::uintptr_t m_srcGraph;|          ^~~~~~~~~
D:/myApp/opencv460/opencv-4.6.0/build/3rdparty/ade/ade-0.1.1f/sources/ade/include/ade/typed_graph.hpp:22:1: note: 'std::uintptr_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?21 | #include "typed_metadata.hpp"+++ |+#include <cstdint>

这是因为ade库用到了std::uintptr_t,std::uintptr_t在cstdint头文件中。但是它没有包含cstdint头文件,需要手动添加。(编译报错的提示还是很有用的)

3. 安装

mingw32-make install
D:\myApp\opencv460\opencv-4.6.0\build>mingw32-make install
[  0%] Built target opencv_highgui_plugins
[  2%] Built target libopenjp2
[  2%] Built target opencv_videoio_plugins
[  3%] Built target zlib
[  9%] Built target opencv_core
[ 15%] Built target opencv_imgproc
[ 18%] Built target libjpeg-turbo
[ 25%] Built target libwebp
[ 28%] Built target libtiff
[ 29%] Built target libpng
[ 35%] Built target IlmImf
[ 36%] Built target opencv_imgcodecs
[ 37%] Built target opencv_videoio
[ 37%] Built target opencv_highgui
[ 37%] Built target opencv_ts
[ 40%] Built target opencv_test_core
[ 42%] Built target opencv_perf_core
[ 42%] Built target opencv_flann
[ 42%] Built target opencv_test_flann
[ 46%] Built target opencv_test_imgproc
[ 48%] Built target opencv_perf_imgproc
[ 49%] Built target opencv_ml
[ 50%] Built target opencv_test_ml
[ 51%] Built target opencv_photo
[ 52%] Built target opencv_test_photo
[ 53%] Built target opencv_perf_photo
[ 55%] Built target libprotobuf
[ 64%] Built target opencv_dnn
[ 65%] Built target opencv_test_dnn
[ 65%] Built target opencv_perf_dnn
[ 67%] Built target opencv_features2d
[ 68%] Built target opencv_test_features2d
[ 69%] Built target opencv_perf_features2d
[ 69%] Built target opencv_test_imgcodecs
[ 69%] Built target opencv_perf_imgcodecs
[ 70%] Built target opencv_test_videoio
[ 70%] Built target opencv_perf_videoio
[ 73%] Built target opencv_calib3d
[ 75%] Built target opencv_test_calib3d
[ 76%] Built target opencv_perf_calib3d
[ 76%] Built target opencv_test_highgui
[ 77%] Built target quirc
[ 78%] Built target opencv_objdetect
[ 78%] Built target opencv_test_objdetect
[ 78%] Built target opencv_perf_objdetect
[ 79%] Built target opencv_stitching
[ 79%] Built target opencv_test_stitching
[ 79%] Built target opencv_perf_stitching
[ 80%] Built target opencv_video
[ 81%] Built target opencv_test_video
[ 82%] Built target opencv_perf_video
[ 83%] Built target ade
[ 91%] Built target opencv_gapi
[ 97%] Built target opencv_test_gapi
[ 98%] Built target opencv_perf_gapi
[ 98%] Built target gen_opencv_python_source
[ 99%] Built target opencv_python3
[ 99%] Built target opencv_annotation
[ 99%] Built target opencv_visualisation
[ 99%] Built target opencv_interactive-calibration
[100%] Built target opencv_version
[100%] Built target opencv_version_win32
[100%] Built target opencv_model_diagnostics
Install the project...
-- Install configuration: "Release"
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/opencl-headers-LICENSE.txt
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/ade-LICENSE
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/ffmpeg-license.txt
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/ffmpeg-readme.txt
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/include/opencv2/cvconfig.h
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/include/opencv2/opencv_modules.hpp
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/x64/mingw/lib/OpenCVModules.cmake
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/x64/mingw/lib/OpenCVModules-release.cmake
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/x64/mingw/lib/OpenCVConfig-version.cmake
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/x64/mingw/lib/OpenCVConfig.cmake
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/./OpenCVConfig-version.cmake
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/./OpenCVConfig.cmake
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/./LICENSE
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/./setup_vars_opencv4.cmd
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/zlib-README
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/libjpeg-turbo-README.md
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/libjpeg-turbo-LICENSE.md
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/libjpeg-turbo-README.ijg
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/libtiff-COPYRIGHT
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/libopenjp2-README.md
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/libopenjp2-LICENSE
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/libpng-LICENSE
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/libpng-README
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/openexr-LICENSE
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/openexr-AUTHORS.ilmbase
-- Installing: D:/myApp/opencv460/opencv-4.6.0/build/install/etc/licenses/openexr-AUTHORS.openexr

4. 安装完的结果

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/626263.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

蓝桥杯省赛无忧 编程4 小蓝的漆房

输入 2 5 2 1 1 2 2 1 6 2 1 2 2 3 3 3输出 1 2#include <bits/stdc.h> using namespace std; int main() {int t; cin >> t;for (int i 0, n, k; i < t; i) {cin >> n >> k;vector<int> arr(n);unordered_set<int> s;for (int j 0…

计算机导论05-计算机网络

文章目录 计算机网络基础计算机网络概述计算机网络的概念计算机网络的功能计算机网络的组成 计算机网络的发展计算机网络的类型 网络体系结构网络互联模型OSI/RM结构与功能TCP/IP结构模型TCP/IP与OSI/RM的比较 网络地址与分配IP地址构成子网的划分IPv6 传输介质与网络设备网络传…

构建稳健的Web应用:LAMP 实践

LAMP 介绍 LAMP 代表 Linux、Apache、MySQL 和 PHP/Python/Perl&#xff08;这些选项中一种&#xff09;的组合&#xff0c;用于搭建 Web 应用程序的开发和运行环境。 Linux&#xff1a;作为操作系统的基础&#xff0c;提供整个 LAMP 堆栈的基础。Linux 提供稳定、安全的环境&…

Pytorch基础:数据读取与预处理——调用PyTorch官方数据集

数据读取与预处理——调用PyTorch官方数据集 1. 从网络端下载 FashionMNIST 数据集到本地2. 数据集可视化 1. 从网络端下载 FashionMNIST 数据集到本地 (base) PS C:\Users\孙明阳> conda activate yang (yang) PS C:\Users\孙明阳> python Python 3.11.5 | packaged by…

CSS 水浪按钮

<template><view class="content"><button class="button"><view class="liquid"></view><view class="btn-txt">水浪按钮</view></button></view></template><scrip…

数据结构与算法教程,数据结构C语言版教程!(第四部分、字符串,数据结构中的串存储结构)二

第四部分、字符串&#xff0c;数据结构中的串存储结构 串存储结构&#xff0c;也就是存储字符串的数据结构。 很明显&#xff0c;字符串之间的逻辑关系也是“一对一”&#xff0c;用线性表的思维不难想出&#xff0c;串存储结构也有顺序存储和链式存储。 提到字符串&#xff…

c语言-数据类型(上)

目录 一、数据类型 二、常量与变量 常量&#xff1a; 变量&#xff1a; 三、进制&#xff08;八&#xff0c;十&#xff0c;十六&#xff09; 十进制&#xff1a; 八进制&#xff1a; 十六进制&#xff1a; 四、基本类型 1.整型常量&#xff1a; 2.整型变量&#xff…

C++内存管理机制(侯捷)笔记4(完结)

C内存管理机制&#xff08;侯捷&#xff09; 本文是学习笔记&#xff0c;仅供个人学习使用。如有侵权&#xff0c;请联系删除。 参考链接 Youtube: 侯捷-C内存管理机制 Github课程视频、PPT和源代码: https://github.com/ZachL1/Bilibili-plus 介绍 下面是第四讲和第五讲…

XSS漏洞:xss-labs靶场通关

xss系列往期文章&#xff1a; 初识XSS漏洞-CSDN博客 利用XSS漏洞打cookie-CSDN博客 目录 第一关 第二关 第三关 第四关 第五关 第六关 第七关 第八关 第九关 第十关 第十一关 第十二关 第十三关 第十四关 第十五关 第十六关 第十七关 第十八关 第十九关 …

Unity | AudioSource 无声音

Unity | AudioSource 无声音 你是否也会遇到相同的问题&#xff1f;AudioSource没声音&#xff1f; 解决&#xff1a; 注意查看一下几处声音设置&#xff1a;

XS2180四通道,兼容 IEEE 802.3at/af以太网供电 PSE 控制器 V1.0

XS2180 是一个四通道、供电设备&#xff08; PSE &#xff09;电源控制 器&#xff0c;设计用于 IEEE 802.3at/af 兼容 PSE 。器件提供用 电设备&#xff08; PD &#xff09;检测、分级、限流以及负载断开检测。器 件支持自动工作和软件编程。器件还支持最新二事件分…

宁夏银行关键系统基于OceanBase的创新实践

宁夏银行成立于 1998 年&#xff0c;是宁夏第一家“宁”字号地方商业银行&#xff0c;西部地区第一家以省级行政区命名的地方商业银行。2016 年&#xff0c;被中国人民银行评为宁夏地区系统性重要银行。目前&#xff0c;全行设分支机构 97 家&#xff0c;其中总行营业部 1 家&a…

centos7 arm服务器编译安装PaddlePaddle

前言 随着国产服务器发展&#xff0c;部署项目需要用在国产服务器上&#xff0c;官方教程里面很多没有讲解到&#xff0c;安装过程中出现了各种各样的问题&#xff0c;以下是对官方教程的补充&#xff0c;有什么问题&#xff0c;欢迎指正&#xff01; 一、环境准备 gcc: 8.2版…

BootStrap 实现轮播图

Bootstrap中文网 1、下载BootStrap 2、引入相关文件 在下载好的文件夹中找到下面的文件&#xff0c;复制到自己的项目中并引入 <link rel"stylesheet" href"bootstrap/css/bootstrap.min.css" /><script src"bootstrap/js/jquery.min.js…

【数据结构与算法】之数组系列-20240116

这里写目录标题 一、15. 三数之和二、16. 最接近的三数之和三、49. 字母异位词分组四、53. 最大子数组和五、189. 轮转数组六、179. 最大数 一、15. 三数之和 提示 中等 给你一个整数数组 nums &#xff0c;判断是否存在三元组 [nums[i], nums[j], nums[k]] 满足 i ! j、i ! k…

【教3妹学编程-算法题】3006. 找出数组中的美丽下标 I

3妹&#xff1a;呜呜&#xff0c;烦死了&#xff0c; 脸上长了一个痘 2哥 : 不要在意这些细节嘛&#xff0c;不用管它&#xff0c;过两天自然不就好了。 3妹&#xff1a;切&#xff0c;你不懂&#xff0c;影响这两天的心情哇。 2哥 : 我看你是不急着找工作了啊&#xff0c; 工作…

如何使用服务器?

文章目录 如何使用服务器&#xff1f;一、工具二、第一种方法三、第二种方法四、实例 个人经验 如何使用服务器&#xff1f; 本文详细介绍了如何利用服务器跑模型&#xff0c;具体流程如下&#xff1a; 一、工具 ToDeskPyCharm Professional移动硬盘JetBrains GatewayGit 二…

dp--62. 不同路径/medium 理解度A

62. 不同路径 1、题目2、题目分析3、复杂度最优解代码示例4、抽象与扩展 1、题目 一个机器人位于一个 m x n 网格的左上角 &#xff08;起始点在下图中标记为 “Start” &#xff09;。 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角&#xff08;在下图中…

免费的域名要不要?

前言 eu.org的免费域名相比于其他免费域名注册服务&#xff0c;eu.org的域名后缀更加独特。同时&#xff0c;eu.org的域名注册也比较简单&#xff0c;只需要填写一些基本信息&#xff0c;就可以获得自己的免费域名。 博客地址 免费的域名要不要&#xff1f;-雪饼前言 eu.org…

Sqoop安全性:确保安全的数据传输

确保数据传输的安全性在大数据处理中至关重要。Sqoop作为一个用于数据传输的工具&#xff0c;也提供了多种安全性措施&#xff0c;以确保数据在传输过程中的机密性和完整性。本文将深入探讨Sqoop的安全性特性&#xff0c;提供详细的示例代码和全面的内容&#xff0c;以帮助大家…