MinGW is a collection of freely available and freely distributable Windows specific header files and import libraries, augmenting the GNU Compiler Collection, (GCC), and its associated tools, (GNU binutils). MinGW provides a complete Open Source programming tool set which is suitable for the development of native Windows programs that do not depend on any 3rd-party C runtime DLLs.

Compile OpenCV under MinGW.

MinGW can be used on its own but it is also the "favorite" compiler of the following IDE's:

Compiling OpenCV with MinGW is shown here differently for different versions of OpenCV:

OpenCV 2.2

In order to make OpenCV 2.2 (containing C++ code) work under Windows with Code::Blocks and MinGW, Matthew (mazeus12 on the mailing list) did the following:

As mentioned in "OpenCV-2.2.0-win-README.txt", "OpenCV-2.2.0-win32-vs2010.exe" does not contain binaries for MinGW so they need to be built from the contents in "OpenCV-2.2.0-win.zip".

Steps to build OpenCV 2.2 with Code::Blocks and MinGW:

1. Install Code::Blocks (10.05) with the (MinGW) C++ compiler option. This should among other install the C++ compiler and mingw32-make to "C:\Program Files\CodeBlocks\MinGW\bin" (I also tried to install the latest MinGW using "mingw-get install gcc g++ mingw32-make" from www.mingw.org but I got an error in extracting some files…)

2. Add "C:\Program Files\CodeBlocks\MinGW\bin" to system PATH (at your own judgment: remove any other paths to MinGW (Somehow DevCpp MinGW paths with probable different versions messed up the build process))

3. Install Cmake (2.8)

4. Extract "OpenCV-2.2.0-win.zip" to "C:\OpenCV-2.2.0-win" (It creates a second folder so the final destination looks like that: "C:\OpenCV-2.2.0-win\OpenCV-2.2.0")

5. Run Cmake (cmake-gui)

6. Set the source code: "C:\OpenCV-2.2.0-win\OpenCV-2.2.0"

7. Set where to build the binaries: e.g. "C:\OpenCV2.2MinGW"

8. Press configure

9. Let Cmake create the new folder

10. Specify the generator: MinGW Makefiles

11. Select "Specify native compilers" and click next

12. For C set: C:/Program Files/CodeBlocks/MinGW/bin/gcc.exe

13. For C++ set: C:/Program Files/CodeBlocks/MinGW/bin/g++.exe

14. Click finish

15. In the configuration screen type in "RELEASE" (or "DEBUG" if you want to build a debug version) for "CMAKE_BUILD_TYPE". Select BUILD_EXAMPLES if you want (I didn't change anything else here like "WITH_TBB" or "WITH QT" etc. I'll try that when time comes to use TBB or Qt)

16. Click configure again

17. Click generate

18. Close cmake

19. Go to the command prompt and inside the folder "C:\OpenCV2.2MinGW" type "mingw32-make" and hit enter (takes some time)

20. Then type "mingw32-make install" and hit enter again

21. Open Code::Blocks and create a new C++ project (Configuration similar to the guide: CodeBlocks).

22. In menu: "Project/Build options/Linker settings/Link libraries" add "C:\OpenCV2.2MinGW\lib\libopencv_calib3d220.dll.a" and all the other *.dll.a files in this folder

23. In menu: "Project/Build options/Search directories/Compiler" add "C:\OpenCV2.2MinGW\include" (includes in a new program schould look like this: "#include <opencv2/core/core.hpp>, #include <opencv2/imgproc/imgproc.hpp>, #include <opencv2/highgui/highgui.hpp> etc.")

24. In menu: "Project/Build options/Search directories/Linker" add "C:\OpenCV2.2MinGW\lib"

The otions in steps 22 - 24 can also be added as global options in menu: Settings/Compiler an Debugger/Global compiler settings/..., so they will apply to any project and opened *.cpp file.

25. If necessary, in menu: Settings/Compiler an Debugger/Global compiler settings/Toolchain executables" specify "C:\Program Files\CodeBlocks\MinGW" for the compiler's installation directory.

26. Open a sample file (or import it into the project), e.g. "C:\OpenCV2.2MinGW\samples\cpp\dft.cpp" and built it. (If the *.cpp files do not exist in this folder, you can find them in the initial folder where you extracted "OpenCV-2.2.0-win.zip" i.e. "C:\OpenCV-2.2.0-win\OpenCV-2.2.0\samples\cpp")

27. Add "C:\OpenCV2.2MinGW\bin" to the system path

28. Run the program

OpenCV 2.0 and 2.1

Release package

OpenCV 2.0 and 2.1 are distributed as a package fromsourceforge

Note: This package is only in Release mode (if you want to have the Debug configuration you need to compile it)

Compilation

With its new c++ interface OpenCV needs GCC 4.x (Since version 1.1.0).

You need to download and install MinGW:

Once the installation is done, you can look at the InstallGuide to continue the compilation.

After compilation you need to be sure that you link with the generatedlibcv*.a(static version of shared library), and that yourlibcv*.dllare in thePATH.

Note: You can have in the same folder the *.dll for MinGW, MSVC and OpenCV 1.0.0. However you need to be sure to not mix them during the linking.

Tips

TBB library with MinGW

Since version 2.1, OpenCV use the TBB library to support parallel processing:

To build OpenCV with TBB under MinGW. You should compiled TBB sources with the following command:

make compiler=gcc arch=ia32 runtime=mingw tbb

Then you should set :

Known Bug specific to MinGW

https://code.ros.org/trac/opencv/query?col=id&col=summary&col=type&col=status&col=priority&col=component&col=version&order=priority&summary=~MinGW

Building on Windows using MinGW 3.4.5


OpenCV 1.0

First, you need to download the official release of MinGW at sourceforge.net

You can use directly the win32 binary package (*.dll and *.lib) because C code compile under Microsoft Visual Studio is compatible with MinGW.

However, the VideoSurveillance part can not be used as it include c++ code.

OpenCVWiki: MinGW (last edited 2010-12-09 09:51:38 by MatthewPediaditis)