1,先装cmake,git
sudo apt install cmake git
2,下载opencv源码
git clone https://gitcode.com/gh_mirrors/opencv31/opencv.git
3,修改CMakeLists.txt以使用mingW-w64
在文件开始加入一下内容:
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc-posix)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++-posix)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4,开始编译
mkdir build
cd build
cmake ..
make