Mingw32编译opencv库

news2024/11/17 10:29:22

文章目录

  • 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 build


D:\myApp\opencv460\opencv-4.6.0>cd build


D:\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 modules
  are removed.  Run "cmake --help-policy CMP0148" for policy details.  Use
  the 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.exe

  PYTHON_VERSION_STRING=3.11.5

  Consider providing the 'PYTHON2_EXECUTABLE' variable via CMake command line
  or environment variables

Call 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 type
  101 |     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.coloradmin.cn/o/1386562.html

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

相关文章

如何实现无公网ip固定TCP端口地址远程连接Oracle数据库

文章目录 前言1. 数据库搭建2. 内网穿透2.1 安装cpolar内网穿透2.2 创建隧道映射 3. 公网远程访问4. 配置固定TCP端口地址4.1 保留一个固定的公网TCP端口地址4.2 配置固定公网TCP端口地址4.3 测试使用固定TCP端口地址远程Oracle 前言 Oracle&#xff0c;是甲骨文公司的一款关系…

64位ATT汇编语言学习第一课:汇编和链接

源文件exitTest.s内容如下&#xff1a; # This is the first program .global _start .section .text _start:movq $60,%raxmovq $9,%rdisyscall源文件里边放的就是源代码&#xff0c;而我这里源代码是使用汇编语言写的&#xff0c;都是一些人类都可以阅读的字符。之后需要经过…

【UE Niagara】网格体渲染器初识

目录 效果 步骤 一、创建网格体粒子 二、设置粒子生成速率 三、设置粒子初始大小 四、设置粒子生成的初始位置 五、设置粒子移动速度 六、设置粒子旋转 七、 设置粒子大小变化 效果 步骤 一、创建网格体粒子 新建一个Niagara粒子系统 选择“Simple Sprite Burs…

Ubuntu配置NFS客户端和服务端详解——手把手配置

Ubuntu配置NFS客户端和服务端 如果您想实现远程访问并修改 ROS 主机中 Ubuntu 上的文件&#xff0c;可以通过 NFS挂载的方式。虚拟机上的 Ubuntu 系统可以通过 NFS 的方式来访问 ROS 主机中Ubuntu 系统的文件&#xff0c;NFS 分为服务器挂载和客户端访问。这里虚拟机上的 Ubun…

小型洗衣机怎么用?好用不贵的小型洗衣机推荐

近期&#xff0c;有不少小伙伴都在议论“对于内衣是机洗好&#xff0c;还是手洗”这个问题&#xff0c;对于机洗党认为家用的洗衣机就能清洁干净内衣物&#xff0c;而坚定的手洗党则是认为应该用手去洗&#xff0c;因为机洗的话&#xff0c;其他大件衣服混在一起洗&#xff0c;…

Picturesocial | 开发实践:如何在15分钟内将应用容器化

在常见的软件架构体系中&#xff0c;容器无疑是一个技术热点。有些开发者在工作中熟练使用容器技术&#xff0c;有些可能刚刚开始容器之旅。 面对容器使用经验不同的各类开发者&#xff0c;我们希望通过这个系列文章&#xff0c;由浅入深地介绍如何使用容器技术来构建&#xf…

小白从事光伏行业:如何快速入行?

鹧鸪云 在政策引导和产业链不断优化的背景下&#xff0c;国内光伏市场不断扩大&#xff0c;国际市场中也崭露头角&#xff0c;许多人纷纷进入光伏行业&#xff0c;但是苦于不知如何入手。本文着重于为刚刚进入光伏行业的新手小白介绍进入光伏行业的好办法。 光伏行业利用太阳…

【深度学习I-基础知识】

深度学习I-基础知识 1 基础知识1.1 模型的基本概念1.2 机器学习1.2.1 概率建模1.2.2 核方法1.2.3 决策树、随机森林和梯度提升机 1.3 深度学习1.3.1 张量1.3.2 数据批量1.3.3 张量运算1.3.4 训练过程 1 基础知识 1.1 模型的基本概念 模型是现实世界中一类具有泛化共性的真实系…

2024 外网数字化考试——精准限制只允许访问考试站点

一、适用场景&#xff1a; 1、防止考试作弊。校园内&#xff0c;需要用到外网的某个考试站点时&#xff0c;只允许浏览器访问考试网站&#xff0c;别的网站不允许访问时&#xff08;避免使用搜索引擎搜索参考或答案&#xff09;。 2、网络流量给教学资源&#xff0c;杜绝网络娱…

企业级做项目的流程

目录标题 前言企业做项目的流程 ⭐⭐总结 前言 我们平时在学校里做项目或者大作业的时候&#xff0c;基本上都是个人开发的&#xff0c;即使有小组一起开发&#xff0c;一般也不会遵守开发规范。最近入职一家企业开始实习&#xff0c;才发现开发规范竟然如此重要&#xff0c;因…

【数据结构】排序之归并排序与计数排序

个人主页 &#xff1a; zxctsclrjjjcph 文章封面来自&#xff1a;艺术家–贤海林 如有转载请先通知 目录 1. 前言2. 归并排序2.1 递归实现2.1.1 分析2.1.2 代码实现 2.2 非递归实现2.2.1 分析2.2.2 代码实现 3. 计数排序3.1 分析3.2 代码实现 4. 附代码4.1 Sort.h4.2 Sort.c4.3…

2. 示例:Spring Boot 入门

1.1 概述 Spring Boot是由Pivotal团队提供的全新框架&#xff0c;其设计目的是用来简化新Spring应用的初始搭建以及开发过程。习惯优于配置 1.2 为什么使用Spring Boot J2EE笨重的开发、繁多的配置、低下的开发效率、复杂的部署流程、第三方技术集成难度大。 1.3 Spring Bo…

【python】进阶--->MySQL数据库(四)

一、主键约束 primary key : 唯一标识数据库中的每一条记录. 被主键的值唯一 主键列不能为null 每个表应该都要设置主键添加主键约束 在创建表时,直接在字段后面添加主键约束 create table 表名 (字段名 类型(长度) primary key )创建表时,不直接在字段后面添加主键…

二、Spring Boot与Mybatis代码自动生成

一、Mybatis代码自动生成 下载自动生成java包&#xff1a;https://www.alipan.com/s/7sGR9uGKoVh 下面就是根据这个进行简单配置即可 1.修改 下面主要修改这个文件 如下 如下 如下 运行 2.结果 解释&#xff1a;在运行之后&#xff0c;就会在上面输入的包里面创建…

【ubuntu】docker中如何ping其他ip或外网

docker中如何ping其他ip或外网 示例图&#xff1a; 运行下面命令&#xff1a; docker run -it --namehei busybox看情况需要加权限 sudo&#xff0c;即&#xff1a; sudo docker run -it --namehei busyboxping 外网 ping -c 4 www.baidu.comping 内网 ping -c 4 192.168.…

rime中州韵小狼毫 联想词组 滤镜

教程目录&#xff1a;rime中州韵小狼毫须鼠管安装配置教程 保姆级教程 100增强功能配置教程 在 rime中州韵小狼毫 自定义词典 一文中&#xff0c;我们分享了如何在rime中州韵小狼毫须鼠管输入法中定义用户自定义词典&#xff1b;通过自定义词典&#xff0c;我们可以很方便的在…

LeetCode:82. 删除排序链表中的重复元素 II(C++、Java)

目录 82. 删除排序链表中的重复元素 II 题目描述&#xff1a; 实现代码与解析&#xff1a; 链表遍历&#xff1a; 实现代码与解析&#xff1a; 82. 删除排序链表中的重复元素 II 题目描述&#xff1a; 给定一个已排序的链表的头 head &#xff0c; 删除原始链表中所有重复…

【我与Java的成长记】之继承详解(二)

系列文章目录 能看懂文字就能明白系列 C语言笔记传送门 Java笔记传送门 &#x1f31f; 个人主页&#xff1a;古德猫宁- &#x1f308; 信念如阳光&#xff0c;照亮前行的每一步 文章目录 系列文章目录&#x1f308; *信念如阳光&#xff0c;照亮前行的每一步* 前言一、super关…

VBA之Excel应用第五节:录制宏时,使用绝对引用和相对引用

《VBA之Excel应用》&#xff08;版权10178983&#xff09;是非常经典的&#xff0c;是我推出的第七套教程&#xff0c;定位于初级&#xff0c;目前是第一版修订。这套教程从简单的录制宏开始讲解&#xff0c;一直到窗体的搭建&#xff0c;内容丰富&#xff0c;实例众多。大家可…

乡镇景区外卖需求的上涨,现在下场做外卖平台服务晚不晚?

如今&#xff0c;在田间地头点外卖已经变成了现实。随着外卖市场的发展&#xff0c;外卖消费的多样化场景逐渐显现&#xff0c;不仅在田间可以订餐外卖&#xff0c;出门旅行的任何地方都可以点上一份热腾腾的外卖送到面前。特别是从去年开始旅游经济恢复之后&#xff0c;外卖也…