Compiling glibmm on Windows

written on Fri 02 November 2012

Here is a short list of steps which need to be taken to successfully install the glibmm library, using gcc 4.7.1, in Windows environment. Use-case scenario for this install would be to use a virtual machine, not a physical one. In the case anyone would choose to use real system, all configuration steps should be changed to include the --prefix option, to avoid creating mess in the system. Also, by using prefixes you will be able to remove everything later by only deleting one directory.

Primary requirements are:

  1. MinGW ("MinGW Shell"),
  2. TDM-GCC, which was v4.7.1 in the time of writing this post.

Step 1: zlib

Zlib, which compiles normally, according to the instructions shown on the screen:

$ make -f win32/Makefile.gcc

Step 2: iconv

Iconv, also installs normally:

$ ./configure
$ make
$ make install

Step 3: gettext

Gettext. First, the configure step needs to be taken:

$ CPPFLAGS="-I /usr/local/include" LDFLAGS="-L/usr/local/lib" ./configure

If you're getting any errors about suporfluous space between -L and /usr/local/lib, you need to manually amend Makefile and remove this space from the file. You can use this oneliner to accomplish this task:

$ find . -iname 'Makefile' -exec sed -i "{}" -e 's/-L /-L/g' \;

It should fix the problem. Last step is to run the compilation and installation, without further complications:

$ make && make install

Step 4: glib

Glib. All you need to do is to inform configure script about the existence of library dependencies. In the place of /c/gnome, insert your own path, where sources of the dependencies are located.

$ CPPFLAGS="-I /c/gnome/gettext/gettext-0.18.1.1/gettext-runtime/intl -I/c/gnome/zlib/zlib-1.2.7" LDFLAGS="-L/c/gnome/zlib/zlib-1.2.7 -L/c/gnome/gettext/gettext-0.18.1.1/gettext-runtime/intl/.libs" ./configure
$ make
$ make install

Step 5: mm-common

mmcommon macro set -- they can be downloaded by git. The configure script should download any dependencies, so you need to enable networking in your virtual machine.

$ ./autogen.sh
$ ./configure --enable-network
$ make && make install

Step 6: pkg-config

PkgConf. Easiest way is to use its internal glib when compiling. The -march=i486 option is required (but you can try to use a higher setting if you want).

$ CFLAGS="-march=i486" ./configure --with-internal-glib
$ make
$ make install

Step 7: libsigc++

Sigc++. It is an important dependency of glibmm, because it's the core of signal and slot mechanism. The library itself seems to be quite complicated, but the usage is rather simple. Luckily, the compilation is trivial.

$ ./configure
$ make && make install

Step 8: glibmm

Glibmm. I suspect that the version of the glibmm library must match the version of glib ({glib}) from step 4.

First, we need to use autogen.sh while pointing it to the m4 macro collection from mm-common macro set (installed in step 5). Then, we need to invoke the configure script remembering that TDM-GCC uses the C++11 standard by default. This is the reason why I'm using the CXXFLAGS environment variable, where I've used the -std=c++03 option, to turn off C++11. I'm not sure if this step is necessary -- in case of any errors you should get rid of this option. Just be aware that C++11 used in tdm-gcc 4.7 breaks some binary compatibility between the previous, 4.6, version, so i.e. the <list> class in C++11 got some new fields. After succesfull (I hope) compilation, you need to open up the config.h file and place #undef 's for these symbols:

#undef GLIBMM_HAVE_WIDE_STREAM
#undef GLIBMM_HAVE_ALLOWS_STATIC_INLINE_NPOS

Best would be to use the appropriate places for these directives (just use the Find option of your favorite text editor).

So, the list of steps:

$ ACLOCAL_FLAGS="-I /usr/local/share/aclocal" ./autogen.sh
$ CXXFLAGS="-std=c++03" ./configure

# remember about #undef's!

$ make install

For the last make install to work, you need to install the doxygen and xsltproc packages. The reason for this is that the pkg-config definition files (.pc) are installed after installing the documentation, which needs to be generated first. Not the best idea, but probably the sequence was generated automatically and since it doesn't make any problems for anybody, probably noone really cares about it.

Testing

This should do the trick. Now you should have the glibmm library installed, together with the pkg-config definition files, so compilation of your sources should work:

$ g++ glibmmtest.cpp -o glibmmtest `pkg-config --cflags --libs glibmm-2.4`
$ ./glibmmtest
Hello, world

Here's the source for glibmmtest.cpp:

#include <stdio.h>
#include <glibmm.h>

int main(int argc, char *argv[]) {
    Glib::thread_init();
    Glib::Mutex m;
    Glib::ustring testStr = "Hello, world\n";
    ::printf("%s", testStr.c_str());
    return 0;
}

This entry was tagged on #linux