Mingw32 4.7, C++11, GNU++11 and various compiling issues

C++ has changed quite a lot since the 1998 standardization. To enjoy the convenient provided by the new C++11 standard, one will need to recompile many external libraries in order to link with newly written code. Yet, there are some tricks and pitfalls here and there in the rebuild process.

Building POCO Library 1.4.5

POCO 1.4.4 is not compatible with ++11. Version 1.4.5 provided partial fix, but still give error when compiling with MinGW in MSYS. To get it compiled with ++11 compliance, the following changes are required:

  • under C:\<your path>\poco-1.4.5\Foundation\src, edit NumberParser.cpp and NumberFormatter.cpp. Replace “I64_FMT” with ” I64_FMT “, i.e. place a space between the double quotes and I64_FMT.
  • under C:\<your path>\poco-1.4.5\build\rules, find the file global. Delete $(BINEXT) from line 262
  • under C:\<your path>\poco-1.4.5\build\config, find the file MinGW. Delete all instance of -mno-cygwin. If you do not use SSL, also delete -lssl and -lcrypto from line 74
  • when using ./configure, pass the argument –cflags=std=gnu++11
  • when using make, do not use the -j switch. Using -j may cause freeze.

 

  Building the IBM internationalization library, ICU4C50.1

The version released in early November 2012 is somewhat incompatible with GCC compiler and its derivatives, like MinGW. To build it with GCC and the like, manually edit the source according to the changes appeared here:

Patch for ICU4C Library 50.1: http://bugs.icu-project.org/trac/changeset/32780

The -std=gnu++11 switch

While many people aware of the flag gnu++0x, it may take quite a while to notice that the more recent version of GCC compiler accept the flag gnu++11. In some occasion, compiling with -std=c++11 will fail but fine with the flag -std=gnu++11, such as wxWidgets2.8.(you’ll probably need to rebuild this library with C++11 compatibility if you use wxPack to install). The differences between c++11 and gnu++11 can be found at http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Extensions.html.

Example:

mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1 CXXFLAGS=-std=gnu++11 -fno-keep-inline-dllexport -j6

some explanations:

  • When using MONOLITHIC=1, there may be a “memory exhausted” problem for the official version of MinGW. If such error does appear, first CLEAN the intermediate files (the command is simply the above command line with the word clean at the end), then re-run make with the -fno-keep-inline-dllexport option added to CXXFLAGS.
  • Note that -std=c++11 may cause compilation failure, use gnu++11 instead.
  • The use of -j# is highly recommend (at least -j2 even for low-end PC) since that will greatly speedup the build process. FYI, compiling wxWidget2.8 with the command line shown above using a PC with Core i7-2600k, 4GB RAM, 32bit-Win7, takes around 10 minutes.