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 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. 安装完的结果

在这里插入图片描述

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

货拉拉智能监控实践:如何解决多云架构下的故障应急问题?

一分钟精华速览 在月活超千万的大规模业务背景下&#xff0c;货拉拉遭遇了多云环境下的监控碎片化、规划无序等问题。为了应对这些挑战&#xff0c;货拉拉开发了一站式监控平台——Monitor。该平台的部署有效地实现了对核心应用的监控和报警全覆盖&#xff0c;显著提高了应急响…

【算法Hot100系列】组合总和

💝💝💝欢迎来到我的博客,很高兴能够在这里和您见面!希望您在这里可以感受到一份轻松愉快的氛围,不仅可以获得有趣的内容和知识,也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学习,不断总结,共同进步,活到老学到老导航 檀越剑指大厂系列:全面总结 jav…

【算法】七夕祭

题目 七夕节因牛郎织女的传说而被扣上了「情人节」的帽子。 于是 TYVJ 今年举办了一次线下七夕祭。 Vani 同学今年成功邀请到了 cl 同学陪他来共度七夕&#xff0c;于是他们决定去 TYVJ 七夕祭游玩。 TYVJ 七夕祭和 11 区的夏祭的形式很像。 矩形的祭典会场由 N 排 M 列共…

作业--day45

定时播放 #include "mywidget.h" #include "ui_mywidget.h"MyWidget::MyWidget(QWidget *parent) :QWidget(parent),ui(new Ui::MyWidget) {ui->setupUi(this);ui->bg_lab->setPixmap(QPixmap(":/pictrue/shanChuan.jpg"));ui->bg_…

装饰器模式

装饰器模式 什么是装饰器模式: 是一种结构型设计模型&#xff0c;允许在不改变对象结构的情况下&#xff0c;动态的将新的功能添加到对象上&#xff0c; 核心思想&#xff1a; 通过组合而非继承的方式来实现功能的扩展。他可以在运行时动态的添加活移除对象的功能&#xff…

刷题第十六天-扰乱字符串

扰乱字符串 题目要求 解题思路 初步分析 给定两个字符串T和S&#xff0c;假设T是由S变换而来的 如果T和S长度不一样&#xff0c;必定不能变来如果长度一样&#xff0c;顶层字符串S能够划分 S 1 S_1 S1​和 S 2 S_2 S2​&#xff0c;同样字符串T也能够划分为 T 1 T_1 T1​和…

[问题记录] vue-router中导航守卫默认跳转login失败

问题 做博客后台的时候发现一个问题&#xff0c;在没启动服务的情况下&#xff0c;后台在 router 中并未读取到配置的情况下&#xff0c;应该默认跳转 login 页面。但是页面始终不跳转&#xff0c;并且伴随多个执行错误弹窗。 router.beforeEach(async (to, from, next) >…

常见类型的yaml文件如何编写?--kind: Job|CronJob

本次介绍两个关联度很高的类型&#xff0c;Job和CronJob。 Job基本说明 在 Kubernetes 中&#xff0c;Job 是一种用于运行一次性任务的资源对象。它用于确保在集群内部执行某个任务&#xff0c;即使任务运行失败或其中一个 Pod 发生故障时&#xff0c;也会进行重试。Job 可以…

软件测试|使用Pytest、Allure Step和Allure Attach创建详细测试报告

引言 在软件开发过程中&#xff0c;测试是不可或缺的一部分。为了更好地展示测试结果并定位问题&#xff0c;结合Pytest测试框架和Allure测试报告工具可以创建清晰、详细的测试报告。本文将介绍如何使用Pytest、Allure的allure.step()和allure.attach()功能来创建具有丰富信息…

AI嵌入式K210项目(2)-开发环境搭建

文章目录 前言windows开发环境&#xff08;vscode&#xff09;VSCode下载安装CMake下载安装交叉编译器Toolchain下载安装SDK下载安装Kflash下载安装镜像烧录 总结 前言 该教程先介绍使用C语言进行裸机开发&#xff0c;完成这一部分的学习之后在介绍如何使用MicroPython进行开发…

Django 框架添加管理员,完成对普通用户信息管理

前情回顾&#xff1a;Django框架 完成用户登录注册 文章目录 1.创建管理员2.完善管理员功能2.1增加管理员登录功能2.2完善展示用户信息功能2.3完善修改用户信息功能2.4完善删除用户信息功能 1.创建管理员 一般管理员都是直接指定&#xff0c;不开放页面注册&#xff0c;可以直…

工程机械比例阀电流采集方案——IPEhub2与IPEmotion APP

自从国家实施一带一路和新基建计划以来&#xff0c;工程机械的需求量呈现出快速增长的趋势。而关于工程机械&#xff0c;其比例阀的控制问题不容忽视。比例阀是一种新型的液压控制装置——在普通压力阀、流量阀和方向阀上&#xff0c;用比例电磁铁替代原有的控制部分&#xff0…

大创项目推荐 深度学习机器视觉车道线识别与检测 -自动驾驶

文章目录 1 前言2 先上成果3 车道线4 问题抽象(建立模型)5 帧掩码(Frame Mask)6 车道检测的图像预处理7 图像阈值化8 霍夫线变换9 实现车道检测9.1 帧掩码创建9.2 图像预处理9.2.1 图像阈值化9.2.2 霍夫线变换 最后 1 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分…

C++ λ表达式

λ表达式提供了函数对象的另一种编程机制。 在 C 11 和更高版本中&#xff0c;Lambda 表达式&#xff08;通常称为 Lambda&#xff09;是一种在被调用的位置或作为参数传递给函数的位置定义匿名函数对象&#xff08;闭包&#xff09;的简便方法。 Lambda 通常用于封装传递给算法…

LLVM的安装步骤实战

目录 1. 准备环境 1.1 安装必备软件包 1.2 配置Git 2. 用CMake构建 2.1 克隆代码库 2.2 创建构建目录 2.3 生成构建系统文件 3. 自定义构建 3.1 CMake定义的变量 3.2 LLVM定义的变量 4. 总结 1. 准备环境 首先操作系统可以是Linux、FreeBSD、macOS或Windows。 同…

Python基础(二十四、JSON和pyecharts)

文章目录 一、JSON1.JSON介绍2.JSON格式数据转化3.示例 二、pyecharts1.安装pyecharts包2.查看官方示例 三、开发示例 一、JSON 1.JSON介绍 JSON是一种轻量级的数据交互格式&#xff0c;采用完全独立于编程语言的文本格式来存储和表示数据&#xff08;就是字符串&#xff09;…

邻接矩阵、可达性矩阵、完全关联矩阵、可达性矩阵的计算

邻接矩阵&#xff1a;很简单&#xff0c;就是两个点有关系就是1&#xff0c;没有关系就是0 可达性矩阵&#xff1a;非常简单&#xff0c;两点之间有路为1&#xff0c;没有路为0 可发行矩阵的计算&#xff1a;有n个元素&#xff0c;初始可达性矩阵为A&#xff0c;那么最终的矩阵…

实战环境搭建-linux下安装tomcat

安装tomcat Index of /dist/tomcat/tomcat-9/v9.0.8/bin 下载apache-tomcat-9.0.8.tar.gz&#xff0c;可以使用wget; 2、将压缩包tar -zxvf apache-tomcat-9.0.8.tar.gz解压到/home/tomcat 3、修改环境变量 vi /etc/profile export JAVA_HOME/home/java/jdk1.8.0_221 expo…

C++ 深度优先搜索DFS || 模版题:排列数字

给定一个整数 n &#xff0c;将数字 1∼n 排成一排&#xff0c;将会有很多种排列方法。 现在&#xff0c;请你按照字典序将所有的排列方法输出。 输入格式 共一行&#xff0c;包含一个整数 n 。 输出格式 按字典序输出所有排列方案&#xff0c;每个方案占一行。 数据范围 1…

力扣热题 100

文章目录 哈希双指针滑动窗口子串普通数组矩阵链表二叉树图论回溯二分查找栈堆贪心算法动态规划多维动态规划技巧 哈希 双指针 移动零 class Solution {public void moveZeroes(int[] nums) {int k 0;for(int i 0;i < nums.length; i){if(nums[i] ! 0) {nums[k] nums[…