Saturday, January 19, 2013

Building OpenCV Libraries for Linux on Windows Using MinGW and MSYS

Purpose
This article delineates 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 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
  • Upzip the downloaded OpenCV scource code to a directory of your choice.
  • Create an output directory where the generated binaries 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.

2 comments:

  1. i have followed the same procedure and i can compile and run opencv programs on windows successfully using Eclipse IDE. But when i try to crosscompile OPENCV programs by pasting the binary file on Raspberry Pi (Linux having ARM processor) i get an error telling that "cannot execute binary file " . Please help me.

    ReplyDelete
  2. Greetings Vijay,

    Thanks for the excellent post. I am curious, have you actually used this to cross compile to an ARM target? I ask because the process doesn't appear to use a cross compiler anywhere, and what gets generated to the install folder is DLL files and library files, all in an 'x86' folder. While I could see the library files being usable in Linux on a desktop, can they be used on ARM? Do you have any example programs using the results of this process for an ARM target? Any help appreciated, and please keep up the great work. Thanks!

    ReplyDelete

ShareThis