L PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> MinGW (64 bit) how-to
last updated: 2024-01-18
Back to the Gaia-SINS home page

Index of contents


the MinGW64 + MSYS2 environment

MinGW64 is an open source C/C++ compiler for WIndows platforms based on the popular gcc available on Linux and on many other Operating Systems; Mingw64 can create both 32 and 64 bit binary executables.
MSYS2 is a command shell supporting a minimalistic Linux-like environment on Windows.
Using both them you can build standard open source software [originally developed for Linux] under Windows as well, simply using the classic build tool-chain, as in:

./configure
make
make install

Quite obviously, Windows isn't exactly the same as Linux, so you cannot expect to get always an easy and painless build.
May well be you have to adapt something here and there in order to get a successful build under Windows.
The following notes are aimed exactly to this goal: allow you to avoid wasting your time while fighting against oddities that can quite easily solved.

Important notice: all the following instructions require using the most recent versions of the compiler (i.e. gcc 13.2.0).

In order to check the actual version you are using, you simply have to execute the following command: gcc --version


The most recent versions of MinGW64 and MSYS2 are reasonably easy to install; just follow the instructions below.

Installing MSYS2

  1. download the MSYS2 intaller from here
  2. start the installer: I suggest you to set C:/dev/msys64 as the base installation path.
  3. once MSYS2 has been installed you must complete several further steps.
    Please follow the instructions you can find here
  4. Note: MSYS2 is a common shell environment supporting both the 32 bit and the 64 bit compilers, so you have to perform this step just once.

Familiarizing with pacman

After properly installing MSYS2 you'll be able to use pacman in order to complete your installation.
Pacman is a package manager similar to Red Hat's yum and Debian's apt-get, and will make really easy the task to prepare a complete build environment.
  1. Start an MSYS2 shell.
    Just click the icon of one between msys2.exe, mingw32.exe or mingw64.exe you'll find into the C:\dev\msys64 folder (the one or the other is not relevant in this context).
  2. Then execute the following commands from the shell:
  3. all right: you've now completed your MinGW64 + MSYS2 installation, and you are ready to start building your Windows binary executables.
Note: may well be you'll discover before or after that some tool is still missing. You can easily install it when required.
Example: the well known vim text editor is still missing; you can easily install it by executing: pacman -S vim
Hint: you can easily check all packages declaring a matching name and if they are already installed or not by executing: pacman -Ss package-name:

Understanding the two build environments: mingw32 and mingw64

In order to mantain a properly ordered filesystem layout, clearly separating 32 bit and 64 bit components we can't any longer adopt the classic /usr/local target as the standard destination where to install our custom builds.

Very important notice

The standard configuration adopted by MinGW64 forbids to effectively link libpthread as a static library.
You are required to manually apply the following small patch in order to avoid this issue.
  • this patch must be applied twice, once for the 32 bit compiler and once for the 64 bit compiler.
  • you must edit the /mingw32/include/pthread.h header file for the 32 bit compiler.
  • and/or you must edit the /mingw64/include/pthread.h header file for the 64 bit compiler.
Near line 85:
  #if defined DLL_EXPORT
  #ifdef IN_WINPTHREAD
  #define WINPTHREAD_API __declspec(dllexport)
  #else
< #define WINPTHREAD_API __declspec(dllimport)
> #define WINPTHREAD_API
  #endif
  #else
  #define WINPTHREAD_API
  #endif



Step 1) building libiconv

libiconv is the standard GNU library supporting locale charsets.
Required by: libspatialite, spatialite-tools

Building under Windows is not too much difficult. cd libiconv-1.17
./configure --prefix=/mingw64/local
make
make install-strip

Anyway, this will simply build and install the DLL: a further step is required in order to get the static library as well.

make distclean
./configure --prefix=/mingw64/local --disable-shared --enable-static
make
make install-strip

Now you've built and installed both the static library and the DLL.
However the above process has installed badly misconfigured libcharset.la and libiconv.la files
(which are required to build other libraries in the following steps).
So in order to get a properly configured libiconv you have to accomplish a further operation:

Step 2) building libz

libz is a popular library implementing Deflate, i.e. the compression algorithm used by gzip and Zip.
Depends on: nothing
Required by: libpng, libtiff, ...

Building under Windows is quite easy, but requires to pay some attenction. cd zlib-1.3
export "INCLUDE_PATH=/mingw64/local/include"
export "LIBRARY_PATH=/mingw64/local/lib"
export "BINARY_PATH=/mingw64/local/bin"
make -f win32/Makefile.gcc
make install -f win32/Makefile.gcc
cp libz.dll.a /mingw64/local/lib
cp zlib1.dll /mingw64/local/bin

All this will build and install both the static library and the DLL as well.
Anyway this process will not generate the libz.la file (which is required to build libtiff in one of the following steps).
So in order to get a fully installed libz you have to accomplish a further operation:

Step 3) building libjpeg

libjpeg is a popular library supporting the JPEG image compression.
Depends on: nothing
Required by: libtiff, librasterlite2

Building under Windows is absolutely a plain and easy task.

Warning

In order to support hi-speed image compression and decompression some parts of jpeg-turbo require to be compiled by the NASM Assembler.
If the Assembler is not installed when building you'll still get a functioning library but operating at a lower speed.

So, if you haven't already installed the NASM Assembler, you just have to execute now the following command on the MSYS2 shell:
pacman -S nasm

cd libjpeg-turbo-3.0.1
mkdir msys_build
cd msys_build
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local ..
make
make install/strip

This will build and install both the static library and the DLL as well.

Anyway this process will not generate the libjpeg.la file (which is required to build libtiff in one of the following steps).
So in order to get a fully installed libjpeg-turbo you have to accomplish a further operation:

Step 4) building libpng

libpng is a popular library supporting the PNG image compression.
Depends on: libz
Required by: librasterlite2

Building under Windows is absolutely a plain and easy task. cd libpng-1.6.40
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local
make
make install-strip

Important notice: you have to properly set the shell environment in order to retrieve the already installed libz; this is the duty of the two above export directives.

This will build and install both the static library and the DLL as well.


Step 5) building giflib

giflib is a popular library supporting the GIF image compression.
Depends on: nothing
Required by: librasterlite2, ...

Building under Windows is absolutely a plain and easy task.
Very important notice: recent versions of this library has no build scripts.
Just a Makefile is supplied, but unhappily it's only intended for Linux and is absolutely useless for MinGW on Windows.

Resolving this issue isn't difficult at all: you are simply required to download Makefile-giflib-mingw64 saving it into the main directory of giflib.

cd giflib-5.2.1
make -f Makefile-giflib-mingw64
make -f Makefile-giflib-mingw64 install

This will build and install both the static library and the DLL as well.

Anyway this process will not generate the libgif.la file (which is required to build libleptonica in one of the following steps).
So in order to get a fully installed libgif you have to accomplish a further operation:

Step 6) building XZ (liblzma)

liblzma is a popular library supporting the LZMA advanced compression (it's a component of the XZ package).
Depends on: nothing
Required by: libtiff

Building under Windows is absolutely a plain and easy task. cd xz-5.4.5
./configure --prefix=/mingw64/local --with-libiconv-prefix=/mingw64/local --with-libintl-prefix=/mingw64/local
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 7) building liblz4

liblz4 is an innovative library supporting very fast lossless data compression and decompression.
Depends on: nothing
Required by: librasterlite2

Building under Windows is absolutely a plain and easy task.
It only has the rather unusual characteristics to adopt CMake-based build scripts, so you'll probably be required to install CMake before attempting to build LZ4.
Anyway you can easily download the most recent CMake Windows Installer from here cd lz4-1.9.4/build/cmake
mkdir build_dll
cd build_dll
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local ..
make
make install/strip

Please note: this will build and install the DLL alone. Now you must build the static library as follows:

cd ..
mkdir build_static
cd build_static
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local -DBUILD_SHARED_LIBS=OFF ..
make
make install/strip

This will build and install both the static library and the DLL as well.


Step 8) building libzstd

libzstd is an innovative library supporting fast lossless data compression and decompression.
Depends on: nothing
Required by: libtiff, librasterlite2

Building under Windows is absolutely a plain and easy task.
It only has the rather unusual characteristics to adopt CMake-based build scripts, so you'll probably be required to install CMake before attempting to build ZSTD.
Anyway you can easily download the most recent CMake Windows Installer from here cd zstd-1.5.5/build/cmake
mkdir build
cd build
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local ..
make
make install/strip

This will build and install both the static library and the DLL as well.


Step 9) building libtiff

libtiff is a popular library supporting the TIFF image format.
Depends on: libz, liblzma, libzstd, libjpeg, libwebp
Required by: librasterlite2

Note: there is a circular dependency between libtiff and libwebp
  • libtiff depends on libwebp
  • and libwebp depends on libtiff
So both libraries require to be built two times in order to correctly resolve the circular dependency.
Let's start the first pass.


Building under Windows is absolutely a plain and easy task. cd tiff-4.6.0
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local
make
make install-strip

Important notice: you have to properly set the shell environment in order to retrieve the already installed libz; this is the duty of the two above export directives.

This will build and install both the static library and the DLL as well.


Step 10) building libwebp

libwebp is an innovative library supporting the recently introduced WebP image compression.
Depends on: libjpeg, libpng, libtiff
Required by: libtiff, librasterlite2, ...

Building under Windows is absolutely a plain and easy task. cd libwebp-1.3.2
sh autogen.sh
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local
make
make install-strip

This will build and install both the static library and the DLL as well.

It's now time to start the second pass required by the circular dependency.
  1. rebuilding libtiff once again.
    • Carefully remove all installed components:
      make uninstall
    • Be sure to reset the configuration:
      make distclean
    • Then restart building and installing libtiff from scratch.
  2. The same is for libwebp


Step 11) building libsqlite

libsqlite is the library implementing the SQLite DBMS engine
Depends on: nothing
Required by: libspatialite, librasterlite

Building under Windows is an easy task. cd sqlite-autoconf-3450000
export "CPPFLAGS=-DSQLITE_ENABLE_STAT3=1 -DSQLITE_ENABLE_TREE_EXPLAIN=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1 -DSQLITE_ENABLE_FTS3_PARENTHESIS=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_THREADSAFE=1 -DSQLITE_DQS=0"
./configure --prefix=/mingw64/local
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 12) building OpenSSL

OpenSSL is a well known standard library supporting SSL, i.e. the encrypted HTTPS web protocol.
Depends on: nothing
Required by: libcurl

Building under Windows is a little bit difficult, and requires to pay close attention.
The configure script isn't at all a standard one: please read carefully the following instructions.
tar zxvf openssl-3.2.0.tar.gz
cd openssl-3.2.0
./Configure mingw64 --prefix=/mingw64/local shared
make
make install

This will build and install both the static libraries and the DLLs as well.


Step 13) building libcurl

libcurl is a well known library supporting URLs (networking, web protocols)
Depends on: libz, OpenSSL
Required by: proj, librasterlite2, ...

Building under Windows is an easy task. cd curl-8.5.0
export "LDFLAGS=-L/mingw64/local/lib64 -L/mingw64/local/lib"
./configure --prefix=/mingw64/local --enable-shared=yes --with-zlib=/mingw64/local --disable-tls-srp --disable-rtsp --without-brotli --without-libidn2 --without-libpsl --without-nghttp2 --with-openssl
make
make install-strip

All right; this will build both the static library and the DLL as well..


Step 14) building libproj

libproj is a library supporting coordinate's transformation between different Reference Systems [PROJ]
Depends on: nothing
Required by: libgeotiff, libspatialite, spatialite-tools

Building under Windows is an easy task. cd proj-9.3.1
mkdir build_dll
cd build_dll
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local \
-DCMAKE_CXX_FLAGS=-DCURL_STATICLIB \
-DSQLITE3_INCLUDE_DIR=/mingw64/local/include \
-DSQLITE3_LIBRARY=/mingw64/local/lib/libsqlite3.dll.a \
-DTIFF_INCLUDE_DIR=/mingw64/local/include \
-DTIFF_LIBRARY=/mingw64/local/lib/libtiff.dll.a \
-DCURL_INCLUDE_DIR=/mingw64/local/include/curl \
-DCURL_LIBRARY=/mingw64/local/lib/libcurl.dll.a ..

make
make install/strip

Please note: this will simply build and install the DLL. Now you must build the static library as follows:

cd ..
mkdir build_static
cd build_static
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local \
-DCMAKE_CXX_FLAGS=-DCURL_STATICLIB \
-DBUILD_SHARED_LIBS=OFF \
-DSQLITE3_INCLUDE_DIR=/mingw64/local/include \
-DSQLITE3_LIBRARY=/mingw64/local/lib/libsqlite3.dll.a \
-DTIFF_INCLUDE_DIR=/mingw64/local/include \
-DTIFF_LIBRARY=/mingw64/local/lib/libtiff.dll.a \
-DCURL_INCLUDE_DIR=/mingw64/local/include/curl \
-DCURL_LIBRARY=/mingw64/local/lib/libcurl.dll.a ..

make
make install/strip

All done: now you've built and installed both the static library and the DLL as well.

Anyway this process will not generate the libproj.la file (which is required to build libgeotiff and libspatialite in following steps).
So in order to get a fully installed libproj you have to accomplish a further operation:

Step 15) building libgeotiff

libgeotiff is a library supporting the GeoTIFF raster format
Depends on: libtiff, libproj
Required by: librasterlite2

Building under Windows is an easy task. cd libgeotiff-1.7.1
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local --with-proj --with-libz --with-jpeg
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 16) building libgeos

libgeos is a library representing a C++ porting of JTS [Java Topology Suite].
Depends on: nothing
Required by: libspatialite, spatialite-tools

This library really is an huge and complex piece of software; cd geos-3.12.1
mkdir build_dll
cd build_dll
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local ..
make
make install/strip

Please note: this will build and install the DLL alone. Now you must build the static library as follows:

cd ..
mkdir build_static
cd build_static
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local -DBUILD_SHARED_LIBS=OFF ..
make
make install/strip

All done: now you've built and installed both the static library and the DLL as well.

Anyway this process will not generate the libgeos.la and libgeos_c.la files (which are required to build librttopo and libspatialite in the following steps).
So in order to get a fully installed GEOS you have to accomplish few further operations:

Step 17) building libexpat

libexpat is a well known standard library supporting XML parsing.
Depends on: nothing
Required by: libfontconfig, spatialite-tools, ...

Building under Windows really is a piece-of-cake. cd expat-2.5.0
./configure --prefix=/mingw64/local
make
make install

This will build and install both the static library and the DLL as well.


Step 18) building minizip

minizip is an innovative library supporting direct creation of compressed ZipFile archives.
Depends on: libz
Required by: libspatialite, DataSeltzer, ...

Building under Windows is absolutely a plain and easy task; anyway there is a little preliminary complication.
The MiniZIP library isn't directly distributed as such; it simply is an auxiliary package you'll find within any standard source tarball distribution of zlib (on the contribs folder).
Unhappily the original distribution is a little bit dirty / unfinished, and lacks any accompanying ./configure script (strictly required by MinGW64/MSYS2).
So there are two possible alternatives to circumvent this issue:
  1. build first MiniZIP on some Linux platform. Then create a standard tarball distribution by calling make dist And finally copy this tarball to your Windows platform.
  2. directly download this pre-configured source tarball: minizip-1.2.11.tar.gz
Once you've got the source tarball you can continue following the usual approach: cd minizip-1.2.11
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local
make
make install-strip

Important notice: you have to properly set the shell environment in order to retrieve the already installed libz; this is the duty of the two above export directives.
This will build and install both the static library and the DLL as well.


Step 19) building FreeXL

FreeXL is an utility library implementing read-access for Excel (.xls) spreadsheets
Depends on: libiconv
Required by: spatialite-tools, libspatialite, spatialite-gui

Building under Windows is an easy task. cd freexl-2.0.0
export "CPPFLAGS=-I/mingw64/local/include -DLIBXML2_STATIC"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local
make
make install-strip

This will build and install both the static library and the DLL as well.

Please note: if you wish, you can now execute the complete test coverage in order to verify if your build was fully succesful.
This further step is optional and requires a small extra time, but it's strongly suggested anyway.

make check


Step 20) building ReadOSM

ReadOSM is an utility library supporting OSM datasets parsing
Depends on: libz, libexpat
Required by: spatialite-tools

Building under Windows is an easy task. cd readosm-1.1.0a
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local
make
make install-strip

This will build and install both the static library and the DLL as well.

Please note: if you wish, you can now execute the complete test coverage in order to verify if your build was fully succesful.
This further step is optional and requires a small extra time, but it's strongly suggested anyway.

make check


Step 21) building PostgreSQL

PostgreSQL is a well known enterprise DBMS; building PostgreSQL seems to be a really odd dependency for SpatiaLite (and really is).
Anyway it's required by GDAL/OGR; if you aren't interested in supporting GDAL/OGR you can directy jump to libxml2

Depends on: libz, OpenSSL
Required by: GDAL/OGR
Building under Windows is an easy task. cd postgresql-16.1
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local --without-icu
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 22) building libxml2

libxml2 is the well known XML parser of Gnome. it's an optional dependency for libspatialite.
If you aren't interested in supporting libxml2 you can directy jump to libspatialite

Depends on: libz, libiconv
Required by: libspatialite
Building under Windows is an easy task. cd libxml2-2.12.4
mkdir build_dll
cd build_dll
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local \
-DLIBXML2_WITH_PYTHON=OFF ..
make
make install/strip

Please note: this will build and install the DLL alone. Now you must build the static library as follows:

cd ..
mkdir build_static
cd build_static
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local \
-DLIBXML2_WITH_PYTHON=OFF -DBUILD_SHARED_LIBS=OFF ..

make
make install/strip

This will build and install both the static library and the DLL as well.

Anyway this process will not generate the libxml2.la file (which is required in some of the following steps).
So in order to get a fully installed libxml2 you have to accomplish a further operation:

Step 23) building librttopo

librttopo is a new library implementing several usefull geometry functions and fully supporting ISO-Topology operators.
If you aren't interested in supporting librttopo you can directy jump to libspatialite

Depends on: libgeos
Required by: libspatialite (optional dependency)
Building under Windows is an easy task. cd librttopo
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
sh autogen.sh
./configure --prefix=/mingw64/local --with-geosconfig=/mingw64/local/bin/geos-config
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 24) building libspatialite

libspatialite is the main core of SpatiaLite
Depends on: libiconv, libproj, libgeos, FreeXL
Required by: spatialite-tools, librasterlite2, spatialite-gui, LibreWMS, DataSeltzer

Building under Windows is an easy task. cd libspatialite-5.1.0
export "CPPFLAGS=-I/mingw64/local/include -DLIBXML_STATIC"
export "LDFLAGS=-L/mingw64/local/lib"
export "PKG_CONFIG_PATH=/mingw64/local/lib/pkgconfig"
./configure --prefix=/mingw64/local --with-geosconfig=/mingw64/local/bin/geos-config --target=mingw32
make
make install-strip

Please note: the above example assumes that librttopo is available; if this is not your case you should obviously omit to specify the corresponding build option.

This will build and install both the static library and the DLL as well.

Please note: if you wish, you can now execute the complete test coverage in order to verify if your build was fully succesful.
This further step is optional and requires a small extra time, but it's strongly suggested anyway.

make check


Step 25) building spatialite-tools

spatialite-tools the SpatiaLite command-line management tools
Depends on: libiconv, libproj, libgeos, FreeXL, ReadOSM, libspatialite, libexpat
Building under Windows is an easy task. cd spatialite-tools-5.1.0a
export "CPPFLAGS=-I/mingw64/local/include -DLIBXML_STATIC"
export "LDFLAGS=-L/mingw64/local/lib"
export "PKG_CONFIG_PATH=/mingw64/local/lib/pkgconfig"
./configure --prefix=/mingw64/local --disable-readline --target=mingw32
make
make install-strip

Please note: following the above method you'll get dynamically linked tools [i.e. depending on DLLs].
If you wish instead to build statically linked tools [i.e. self contained, not depending on DLLs], now type:

mkdir static_bin
make -f Makefile-static-mingw64
cp static_bin/* /mingw64/local/bin


Step 26) building wxWidgets MSW

wxWidgets is a popular widgets library, supporting GUI in a cross-platform fashion; MSW is the specific porting supporting Windows.
Depends on: nothing
Required by: spatialite-gui, spatialite-gis

This library really is an huge and complex piece of software; building on Windows is an incredibly time consuming task, but is quite plain and easy. cd wxWidgets-3.2.4
mkdir msw_build
cd msw_build
export "CPPFLAGS=-Wno-narrowing -I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
../configure --prefix=/mingw64/local --disable-shared --disable-debug --enable-monolithic --enable-unicode --without-regex --with-liblzma --enable-graphics_ctx

Please note: the wxWidgets ./configure is highly configurable: you must apply exactly the above settings.
Anyway, when ./configure stops, it's a good practice to check if the final report looks exactly like this:

Configured wxWidgets 3.2.4 for `x86_64-w64-mingw32'

  Which GUI toolkit should wxWidgets use?                 msw
  Should wxWidgets be compiled into single library?       yes
  Should wxWidgets be linked as a shared library?         no
  Should wxWidgets be compiled in Unicode mode?           yes (using wchar_t)
  What level of wxWidgets compatibility should be enabled?
                                       wxWidgets 2.8      no
                                       wxWidgets 3.0      yes
  Which libraries should wxWidgets use?
                                       STL                no
                                       jpeg               sys
                                       png                sys
                                       regex              no
                                       tiff               sys
                                       lzma               sys
                                       zlib               sys
                                       expat              sys
                                       libmspack          no
                                       sdl                no

now, when ./configure stops, you have to continue as usual:

make
make install-strip

Important notice: make install-strip will probably raise some error, but you could safely ignore it at all.


Step 27) building libfreetype

libfreetype is a standard library supporting TrueType fonts.
Depends on: nothing
Required by: libcairo, ...

Building under Windows is an easy task. cd freetype-2.13.2
./configure --prefix=/mingw64/local --with-bzip2=no --with-brotli=no
make
make install

This will build and install both the static library and the DLL as well.


Step 28) building libfontconfig

libfontconfig is a standard library supporting font customization and configuration.
Depends on: libexpat, libfreetype, libiconv
Required by: libcairo, ...

Building under Windows is an easy task. cd fontconfig-2.15.0
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
export "PKG_CONFIG_PATH=/mingw64/local/lib/pkgconfig"
./configure --prefix=/mingw64/local --disable-docs --disable-nls --enable-shared --enable-static
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 29) building libpixman

libpixman is the standard library implementing pixel manipulation for Cairo.
Depends on: nothing
Required by: libcairo, ...

Building under Windows is an easy task.
cd pixman-0.42.2
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
export "PKG_CONFIG_PATH=/mingw64/local/lib/pkgconfig"
./configure --prefix=/mingw64/local
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 30) building libcairo

libcairo is a very popular graphics library.
Depends on: libpixman, libfreetype, libfontconfig, libpng
Required by: librasterlite2, ...

Building under Windows is a little bit harder than usual.
cd cairo-1.16.0
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
export "PKG_CONFIG_PATH=/mingw64/local/lib/pkgconfig"
./configure --prefix=/mingw64/local
make
make install-strip

This will build and install both the static library and the DLL as well.

Important notice: you are required to manually edit the ./configure script in order to avoid a failing link due to unresolved symbols:
Line 19174: replace -D_FORTIFY_SOURCE=2 as: -D_FORTIFY_SOURCE=0


Step 31) building lcms2

lcms2 is an innovative library implementing a Color Management Engine.
Depends on: libjpeg, libpng, libtiff
Required by: OpenJpeg-2

Building under Windows is absolutely a plain and easy task. cd lcms2-2.15
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local
make
make install-strip

Important notice: you have to properly set the shell environment in order to retrieve the already installed libz; this is the duty of the two above export directives.
This will build and install both the static library and the DLL as well.


Step 32) building OpenJpeg-2

OpenJpeg-2 is an open source library supporting Jpeg2000 compressed images.
Depends on: libcms2, libpng, libtiff
Required by: librasterlite2

Building under Windows is absolutely a plain and easy task.
It only has the rather unusual characteristics to adopt CMake-based build scripts, so you'll probably be required to install CMake before attempting to build OpenJpeg.
Anyway you can easily download the most recent CMake Windows Installer from here Important notice: you absolutely have to apply the following patch before attempting to build OpenJpeg.
The intended scope is the one to redefine the DLL's specific prefix accordingly to MinGW64 requirements. So manually edit the -/src/lib/openjp2/openjpeg.h source:
near line 94:
----------------------------------------
   #define OPJ_API
   #define OPJ_LOCAL
   #endif
   #define OPJ_CALLCONV
< #else
< #define OPJ_CALLCONV __stdcall
> #else
> #if defined (__MINGW32__)
> #define OPJ_CALLCONV
> #else
> #define OPJ_CALLCONV __stdcall
> #endif

then you should continue to apply this second patch into the same file:
near line 110:
----------------------------------------
   #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
   #define OPJ_API __declspec(dllexport)
   #else
< #define OPJ_API __declspec(dllimport)
> #if defined (__MINGW32__)
> #define OPJ_API extern
> #else
> #define OPJ_API __declspec(dllimport)
> #endif /* MinGW64 */

cd openjpeg-2.5.0
mkdir build_dll
cd build_dll
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local \
-DBUILD_PKGCONFIG_FILES=ON \
-DZLIB_INCLUDE_DIR=/mingw64/local/include \
-DZLIB_LIBRARY=/mingw64/local/lib/libz.dll.a \
-DPNG_PNG_INCLUDE_DIR=/mingw64/local/include/libpng16 \
-DPNG_LIBRARY=/mingw64/local/lib/libpng16.dll.a \
-DTIFF_INCLUDE_DIR=/mingw64/local/include \
-DTIFF_LIBRARY=/mingw64/local/lib/libtiff.dll.a \
-DLCMS2_INCLUDE_DIR=/mingw64/local/include \
-DLCMS2_LIBRARY=/mingw64/local/lib/liblcms2.dll.a ..

make
make install/strip

Please note: this will simply build and install the DLL. Now you must build the static library as follows:

cd ..
mkdir build_static
cd build_static
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local \
-DBUILD_SHARED_LIBS=OFF \
-DZLIB_INCLUDE_DIR=/mingw64/local/include \
-DZLIB_LIBRARY=/mingw64/local/lib/libz.dll.a \
-DPNG_PNG_INCLUDE_DIR=/mingw64/local/include/libpng16 \
-DPNG_LIBRARY=/mingw64/local/lib/libpng16.dll.a \
-DTIFF_INCLUDE_DIR=/mingw64/local/include \
-DTIFF_LIBRARY=/mingw64/local/lib/libtiff.dll.a \
-DLCMS2_INCLUDE_DIR=/mingw64/local/include \
-DLCMS2_LIBRARY=/mingw64/local/lib/liblcms2.dll.a ..

make openjp2
cp bin/libopenjp2.a /mingw64/local/lib

All done: now you've built and installed both the static library and the DLL as well.

Anyway this process will not generate the libopenjp2.la file (which is required to build libleptonica in one of the following steps).
So in order to get a fully installed libopenjp2 you have to accomplish a further operation:

Step 33) building fcgi2

fcgi2 is a library supporting CGI / FastCGI web interfaces
Depends on: nothing

Required by: librasterlite2

Building under Windows is an easy task.
cd fcgi2-2.4.2
sh ./autogen.sh
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 34) building Leptonica

Leptonica is a library for advanced image processing and image analysis
Depends on: libpng, libjpeg, libtiff, libgif, libwebp, openjepg

Required by: librasterlite2

Building under Windows is an easy task.
cd leptonica-1.84.1
sh ./autogen.sh
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --prefix=/mingw64/local --disable-programs
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 35) building librasterlite2

librasterlite2 is a library supporting rasters
Depends on: libjpeg, libpng, libtiff, libgeotiff, libcairo, libgif, libwebp

Required by: spatialite-gui, LibreWMS

Building under Windows is an easy task.
cd librasterlite2-1.1.0-beta1
export "CPPFLAGS=-I/mingw64/local/include -DCURL_STATICLIB -DLIBXML_STATIC"
export "LDFLAGS=-L/mingw64/local/lib"
export "PKG_CONFIG_PATH=/mingw64/local/lib/pkgconfig"
./configure --prefix=/mingw64/local --target=mingw32
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 36) building libvirtualpg

libvirtualpg is a library supporting VIRTUAL TABLES acting as bridges between SQLite and PostgreSQL/PostGIS.
Depends on: libslite3, libpq

Required by: spatialite-gui

Building under Windows is an easy task.
cd virtualpg-2.0.0
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
export "PKG_CONFIG_PATH=/mingw64/local/lib/pkgconfig"
./configure --prefix=/mingw64/local --target=mingw32 \
        --with-pgconfig=/mingw64/local/bin/pg_config

make
make install-strip

This will build and install both the static library and the DLL as well.


Step 37) building libxlsxwriter

libxlsxwriter is a C library for creating MS Excel XLSX files.
Depends on: libz
Required by: spatialite_gui

Building under Windows is absolutely a plain and easy task.
It only has the rather unusual characteristics to adopt CMake-based build scripts, so you'll probably be required to install CMake before attempting to build libxslxwriter.
Anyway you can easily download the most recent CMake Windows Installer from here cd libxlsxwriter-RELEASE_1.1.5
mkdir build_dll
cd build_dll
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local -DBUILD_SHARED_LIBS=ON ..
make
make install/strip

Please note: this will build and install the DLL alone. Now you must build the static library as follows:

cd ..
mkdir build_static
cd build_static
cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw64/local ..
make
make install/strip

This will build and install both the static library and the DLL as well.


Step 38) building spatialite_gui

spatialite_gui the SpatiaLite GUI user-friendly tool
Depends on: libspatialite, wxWidgets, librasterlite2
Building under Windows is an easy task. cd spatialite_gui-2.1.0-beta1
export "CPPFLAGS=-I/mingw64/local/include -DCURL_STATICLIB"
export "LDFLAGS=-L/mingw64/local/lib"
export "PKG_CONFIG_PATH=/mingw64/local/lib/pkgconfig"
./configure --prefix=/mingw64/local --with-wxconfig=/mingw64/local/bin/wx-config --with-geosconfig=/mingw64/local/bin/geos-config --with-pgconfig=/mingw64/local/bin/pg_config --with-libpq_deferred
make
make install-strip

Please note: following the above method you'll get a dynamically linked GUI tool [i.e. depending on DLLs].
If you wish instead to build a statically linked GUI tool [i.e. self contained, not depending on DLLs], now type:

mkdir static_bin
make -f Makefile-static-mingw64
cp static_bin/* /mingw64/local/bin


Step 39) building libcgi

libcgi is a standard library supporting the CGI environment.
Depends on: nothing
Required by: DataSeltzer

Building under Windows is absolutely a plain and easy task. cd libcgi-1.0
./configure
make
make install

This will build and install both the static library and the DLL as well.


Step 40) building DataSeltzer CGI

DataSeltzer is a CGI component supporting OpenData dissemination built on the top of SpatiaLite.
Building under Windows is an easy task. First of all, you must check if you've already installed pkg-config.exe
If not, please read the above instructions

And now you must set the PKG_CONFIG_PATH as appropriate:

export "PKG_CONFIG_PATH=/mingw64/local/lib/pkgconfig"

After this you are now ready to build as usual:

cd dataseltzer-1.0.0
export "CPPFLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --target=mingw32
make
Please note: following the above method you'll get a dynamically linked CGI component [i.e. depending on DLLs].
If you wish instead to build a statically linked CGI [i.e. self contained, not depending on DLLs], now type:

mkdir static_bin
make -f Makefile-static-MinGW64

Please note: installing a CGI component requires special precautions depending on the specific Web Server configuration.

Step 41) building GDAL

GDAL is the well known Geospatial Data Abstraction library. it's strictly required by mod_gdalsplite.
Depends on: practically all libraries built since now
Required by: mod_gdalsplite
Building under Windows is a very long but easy task. cd gdal-2.0.1
export "CPPLAGS=-I/mingw64/local/include"
export "LDFLAGS=-L/mingw64/local/lib"
./configure --with-liblzma=yes --with-spatialite=yes --with-webp=yes
make
make install-strip

This will build and install both the static library and the DLL as well.


Step 42) building fossil

fossil is the SCM [Source Code Management] used by SpatiaLite (and companion) projects.
Building on Windows is an easy and plain task. Important notice: you are required to manually edit the -/win/Makefile.mingw script as follows:

Line 55: replace # FOSSIL_ENABLE_SSL = 1 as: FOSSIL_ENABLE_SSL = 1
Line 81: replace ZINCDIR = $(SRCDIR)/../zlib-1.2.6 as: ZINCDIR = /mingw64/local/include
Line 82: replace ZLIBDIR = $(SRCDIR)/../zlib-1.2.6 as: ZLIBDIR = /mingw64/local/lib
Line 89: replace OPENSSLINCDIR = $(SRCDIR)/../openssl-1.0.0g/include as: OPENSSLINCDIR = /mingw64/local/include
Line 90: replace OPENSSLLIBDIR = $(SRCDIR)/../openssl-1.0.0g as: OPENSSLLIBDIR = /mingw64/local/lib
Line 661,662: delete both lines
zlib:
    $(MAKE) -C $(ZLIBDIR) PREFIX=$(PREFIX) -f win32/Makefile.gcc libz.a
Line 663: delete zlib at the end of the line.

After this you are now ready to build:

cd fossil-src-20130216000435
make -f win/Makefile.mingw
strip --strip-all fossil.exe


Back to the Gaia-SINS home page
last updated: 2024-01-18