注意:
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 (foun