Part 1 – Preparation
I used to make my OpenCV projects in C++ using Visual Studio on my Windows Machine. However for my next project I wanted to make sure that the project can be build on Linux as well. But, since I do not have a Linux machine, I thought of using GCC Compiler on Cygwin. (If the project works fine on GCC/Cygwin, it should run fine on a Linux machine as well). But it wasn’t as easy as I thought.
Step 1: Install Cygwin
My other blog post explains how-to-install-cygwin-on-windows
Step 2: Install OpenCV libraries for Cygwin
Since my windows machine had Visual Studio specific OpenCV libraries, that can not be used with Cygwin/gcc, I had to install OpenCV libraries for Cygwin separately. I used Cygwin Ports for the installation.
Run the Cygwin Setup setup-x86.exe (or setup-x86_64.exe) and follow instructions upto step 8 of this post. At step 9 of choosing packages, under the “Libs” category, select “libopencv-devel” and “libopencv2.4”, click Next and install these libraries.

Step 3. Install CMake utility
“CMake is cross-platform free and open-source software for managing the build process of software using a compiler-independent method” (from wiki).
Again run the Cygwin Setup setup-x86.exe (or setup-x86_64.exe) and follow instructions upto step 8 of this post. At step 9 of choosing packages, under “Devel” category, select “cmake”, click next and install.

Now you are ready to build your OpenCV projects using Cygwin/GCC. However if your OpenCV projects involve displaying images etc, non command prompt windows, you need to install XServer.
Step 4. Install XServer
Again run the Cygwin Setup setup-x86.exe (or setup-x86_64.exe) and follow instructions upto step 8 of this post. At step 9 of choosing packages, under “X11” category, select “xinit”, “xorg-server”, “xorg-x11-fonts-XXXXX”, click next and install.

Now you are ready to compile and run your OpenCV project under Cygwin. Happy Coding !!!