How to compile open-source libraries under Windows using MinGW

Lots of open source libraries (like libiconv, libintl, …) doesn’t have MSVC project files or makefiles. Only supported way how to compile given library under Window is using MinGW and MSYS compiler tools.

Here is step-by-step guide how to download, install and compile libraries using MinGW.

Step one download MinGW

From MinGW home web site http://www.mingw.org/ download “Automated MinGW Installer”. Current version could be downloaded here: http://sourceforge.net/projects/mingw/files_beta/Automated MinGW Installer

Step two installing

Run downloaded executable. As install directory leave C:\MinGW. It’s recommended not to change this path.  On component screen select C compiler, C++compiler, MSYS Basic System and MinGW Developer Toolkit.

After that select next,next,next, finish ;-). After that installer downloads all necessary files. This could take a few minutes.

When installation is done, as next step is necessary to setup PATH variable to c:\MinGW. Installer doesn’t modify it automatically. (more info about modifying PATH variable) .

Installing additional gcc compiler and make support

These two packages isn’t listed in available components. If you wish to install it, use mingw-get-inst. In c:\MinGW\bin directory run following commands:

mingw-get install gcc g++ mingw32-make msys-base

Step three compiling

Compiling from windows shell

Launch cmd tool, go to directory with source code and use g++.

g++ test.cpp

Compiling from MinGW console

Launching MinGW console

Laung MinGW from startmenu or msys.bat from %INSTALL_PATH%\MinGW\msys\1.0\msys.bat.

How to compile libiconv library

As first, download latest libiconv source files from http://www.gnu.org/software/libiconv. And extract whole package somewhere on your disk.

Launch MinGW console and go to the extracted directory. When you extracted directory to the path:

p:\DependentLibrariesWhole\libiconv-1.13.1

Type following command to MinGW console:

cd /p/DependentLibrariesWhole/libiconv-1.13.1

after that, run configure with required library params (in our case we want static and dynamic version of library):

configure --enable-static --enable-shared

and than run make

make

Compiled libraries are located in directory “libiconv-1.13.1\lib\.libs”. There is  additional information about building libiconv library on stackoverflow.

Additional How to guides

This list is compilation of answer to questions and informations how to solve some problems which I had during my installations.

How to get list of available parameters for configure script?

Use “configure –help” command.