Click here to Skip to main content
15,887,175 members
Articles / Programming Languages / CUDA

Building OpenCV Libraries for Linux on Windows Using MinGW and MSYS

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
23 Jan 2013CPOL2 min read 16.5K   5   2
Procedure to be followed in order to generate OpenCV libraries for Linux operating system using MinGW and MSYS toolkit on Windows Operating system.

Purpose

This article delineates the procedure to be followed in order to generate OpenCV libraries for Linux operating system using MinGW and MSYS toolkit on Windows Operating system.

Why Can't We Directly Build OpenCV Binaries on Linux ?

This is a common question, which broaches up in everyone's mind. Unless we are not generating Windows libraries (DLL or LIB), why are we using this method.

The answer is simple - developers use this method of cross compiling OpenCV, to generate Linux binaries for "ARM" targets running Linux. Considering the hardware and processing limitations of ARM targets, it is absurd to setup development environment on ARM targets. But developers rather prefer to cross compile these binaries for Linux using MinGW and MSYS toolkit on Windows, which curtails efforts on setting up a Linux development environment on ARM real-time targets.

How Do We Build, OpenCV Libraries for Linux on Windows Using MinGW and MSYS ?

Kindly follow the below procedure to generate OpenCV Linux libraries on Windows:

  • Download and install MinGW and MSYS from www.mingw.org.
  • Check the Include Path and Library Path, set it if required.
  • Check the GCC version.

  • Download the OpenCV source code from opencv.org , which redirects to Git repository OpenCV Git Repository
  • Unzip the downloaded OpenCV source code to a directory of your choice.
  • Create an output directory where the generated binaries are to be placed.

  • Install CMake, a tool which generates build configuration files, like Makefile or a Solution file based on the configuration selected.
  • Run the CMake tool, and specify the type of build configuration files to be generated, for Linux we choose "MinGW Makefiles".

  • Now specify the OpenCV source code directory, and build output directory in the CMake tool and select build configurations, like modules to be built, enabling IPP, CUDA, SSE, and many other options based on your requirements.

  • Once the required configuration is selected, click on "Configure" and then "Generate" to get build configuration files.
  • Now open "MinGW" shell and change directory to OpenCV build directory which you have created.

  • Execute command "mingw32-make" to build OpenCV source code.

  • Once the build is complete, run "mingw32-make install" to get all the libraries, included files and documentation in the install folder.

The binaries generated in "Install" folder can be included in any project, which intends to use OpenCV in its source.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
India India
I am Vijay hailing from Bangalore, the silicon valley of India. I posses extensive expertise working in mobility domain. I have a natural propensity for "Research and Innovation".

My areas of interest include Pervasive computing, Cognitive sensors, HCI, and Multimedia. Being strongly resolute with an everlasting fervor for learning, over the years I have learnt to come out of comfort zone to experiment with state of the art technologies and to contribute to developer community.

I blog about innovations and latest technologies from mobility domain, about development environments and programming languages across different platforms.

Blog : Amusement of a speculative mind...[^]
Projects : Amusement of a dilettante mind...[^]
LinkedIn : Vijay D R [^]

Comments and Discussions

 
QuestionBuild OpenCV Library on Vitis HLS 2022.1 on Windows OS Pin
Nikhil B 202227-Sep-22 4:23
Nikhil B 202227-Sep-22 4:23 
Hello,

I've tried to build OpenCV libraries on Vitis HLS, I'm getting errors during the build, request you to pls help me resolving the 2 errors below.
1) After installation on MinGW and adding bin path directory to the environment variables.

2) Installation of OpenCV 4.6.0

3) Installation of CMake

4) OpenCV Source Code Build using CMake, Added the Extracted OpenCV Source directory path on CMake (to Where is the source code) and the Build directory path on Cmake (under Where to build the binaries). Carried out configuration and generation.

5) Finally, Tried to build and install the OpenCV Libraries from the Command prompt using the command mingw32-make install from the Build directory path.

This resulted in the 2 errors above.



What am I doing wrong? What am I missing? How do I resolve the 2 errors?

Kindly pls help.


In file included from C:\Users\Nikhil\Downloads\opencv\sources\modules\core\src\precomp.hpp:53:0,
                 from C:\Users\Nikhil\Downloads\opencv\sources\modules\core\src\algorithm.cpp:43:
C:/Users/Nikhil/Downloads/opencv/sources/modules/core/include/opencv2/core/utility.hpp:718:14: error: 'recursive_mutex' in namespace 'std' does not name a type
 typedef std::recursive_mutex Mutex;
              ^~~~~~~~~~~~~~~
C:/Users/Nikhil/Downloads/opencv/sources/modules/core/include/opencv2/core/utility.hpp:719:25: error: 'Mutex' is not a member of 'cv'
 typedef std::lock_guard<cv::Mutex> AutoLock;
                         ^~
C:/Users/Nikhil/Downloads/opencv/sources/modules/core/include/opencv2/core/utility.hpp:719:25: error: 'Mutex' is not a member of 'cv'
C:/Users/Nikhil/Downloads/opencv/sources/modules/core/include/opencv2/core/utility.hpp:719:34: error: template argument 1 is invalid
 typedef std::lock_guard<cv::Mutex> AutoLock;
                                  ^
In file included from C:\Users\Nikhil\Downloads\opencv\sources\modules\core\src\algorithm.cpp:43:0:
C:\Users\Nikhil\Downloads\opencv\sources\modules\core\src\precomp.hpp:368:5: error: 'Mutex' in namespace 'cv' does not name a type
 cv::Mutex& getInitializationMutex();
     ^~~~~
modules\core\CMakeFiles\opencv_core.dir\build.make:102: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/src/algorithm.cpp.obj' failed
mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/algorithm.cpp.obj] Error 1
CMakeFiles\Makefile2:1805: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:164: recipe for target 'all' failed
mingw32-make: *** [all] Error 2


modified 29-Sep-22 5:02am.

QuestionDo you know how building opencv libraries for WIndows on Linux? Pin
Member 1173707614-Apr-17 5:07
Member 1173707614-Apr-17 5:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.