Building 32 bit and 64 bit wxWidgets libraries for use with Code::Blocks 16.01

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
CJS
Earned a small fee
Earned a small fee
Posts: 17
Joined: Thu Jan 28, 2016 8:21 am

Building 32 bit and 64 bit wxWidgets libraries for use with Code::Blocks 16.01

Post by CJS » Thu Nov 24, 2016 12:42 pm

This post is offered as an example of a working wxWidgets 32 bit and 64 bit build on Windows using MinGW family compilers.

The Code::Blocks 16.01 Windows installer includes a 32 bit C++ compiler and debugger. This can be used for the 32 bit library, which is just as well, because the 64 bit compiler has issues with building in the 32 bit mode that it is supposed to include. Code::Blocks 16.01 doesn't include a 64 bit compiler, so you need to download a separate compiler for 64 bit. If you're not using Code::Blocks, a 32 bit compiler can also be downloaded from http://tdm-gcc.tdragon.net/ or use whatever 32 bit compiler you've already got.

Take care the environment PATH includes ONLY a path to the compiler currently being used. The built-in compiler has a batch file mingwvars.bat that adds the path to the MinGW\bin subdirectory in the Code::Blocks installation.

The following 32 bit builds with the Code::Blocks built-in compiler build libraries for debug and release, static and dynamic builds (see https://wiki.wxwidgets.org/WxWidgets_Bu ... igurations).

You set the command line to the \build\msw subdirectory of the wxWidgets installation and use:

mingw32-make -j8 -f makefile.gcc CXXFLAGS="-std=gnu++11" BUILD=debug UNICODE=1 SHARED=1

mingw32-make -j8 -f makefile.gcc CXXFLAGS="-std=gnu++11" BUILD=release UNICODE=1 SHARED=1

mingw32-make -j8 -f makefile.gcc CXXFLAGS="-std=gnu++11" BUILD=debug UNICODE=1 SHARED=0

mingw32-make -j8 -f makefile.gcc CXXFLAGS="-std=gnu++11" BUILD=release UNICODE=1 SHARED=0

Each build will take some time and produce a lot of diagnostic output (which you can pipe to a file if you prefer).
Compiler and library support for the ISO C++ 2011 standard is enabled with the -std=c++11 or -std=gnu++11 options (the latter includes gnu extensions). Other flags might need adjusting according to your needs.

The "-j8" flag is for maximum speed on an 8 processor system, it needs to be adjusted to the number of available processors (or omitted to compile without multithreading - maybe safer, but slow).

Note: Sometimes a make failed with a "waiting for unfinished jobs" error, however, simply retrying the command resulted in a successful build.

If a prior build exists or you suspect one might exist, you must first run the same command but with "clean", e.g:
mingw32-make -j8 -f makefile.gcc CXXFLAGS="-std=gnu++11" BUILD=debug UNICODE=1 SHARED=1 clean

As a check, you can set the command processor to the \samples\minimal directory in the wxWidgets installation, then run the same mingw32-make command (with the same parameters there), which should create a working minimal wxWidgets sample.

To build the 64 bit libraries, I used the TDM64 MinGW-w64 edition compiler (based on the GNU toolchain), version 5.1.0-2 (see http://tdm-gcc.tdragon.net/download). Fortunately this also includes a 64 bit GDB debugger which can be used with Code::Blocks for debugging 64 bit builds.

To build the 64 bit libraries you now need to make sure that the PATH variable ONLY includes the path to the 64 bit compiler, set the command line to the \build\msw subdirectory of the wxWidgets installation and use:

C:\tdm-gcc-64-5.1.0-2\bin\mingw32-make -j8 -f makefile.gcc CFG=64 CXXFLAGS="-std=gnu++11" BUILD=debug UNICODE=1 SHARED=1

C:\tdm-gcc-64-5.1.0-2\bin\mingw32-make -j8 -f makefile.gcc CFG=64 CXXFLAGS="-std=gnu++11" BUILD=release UNICODE=1 SHARED=1

C:\tdm-gcc-64-5.1.0-2\bin\mingw32-make -j8 -f makefile.gcc CFG=64 CXXFLAGS="-std=gnu++11" BUILD=debug UNICODE=1 SHARED=0

C:\tdm-gcc-64-5.1.0-2\bin\mingw32-make -j8 -f makefile.gcc CFG=64 CXXFLAGS="-std=gnu++11" BUILD=release UNICODE=1 SHARED=0

In this case I used the full path to the mingw32-make executable (but it's probably unessential if that path is in the PATH variable).

If you repeat the minimal sample build, using the 64 bit compiler command:
C:\tdm-gcc-64-5.1.0-2\bin\mingw32-make -j8 -f makefile.gcc CFG=64 CXXFLAGS="-std=gnu++11" BUILD=release UNICODE=1 SHARED=0
- this should create a working 64 bit minimal wxWidgets sample. You should now have the 32 bit minimal.exe in the ...minimal\gcc_mswu subdirectory and the 64 bit minimal.exe in the ...minimal\gcc_mswu64 subdirectory. If you run it, the 32 bit one should show up in Task Manager as "minimal.exe *32" but the 64 bit one should show just as "minimal.exe".

Directories created by tdm-gcc-64 with the CFG=64 flag are named differently to the ones created by the 32 bit compiler so can coexist side by side, e.g. under the wxWidgets \lib\ directory should be \gcc_dll, \gcc_dll64, \gcc_lib and \gcc_lib64, plus object code under \build\msw\gcc_mswu64, \build\msw\gcc_mswud64, \build\msw\gcc_mswuddll64 and \build\msw\gcc_mswudll64.

The differently named directories have the same file names therein, which means you don't have to bother changing every single library module name in the linker configuration lists when you create a 64 bit build from an existing 32 bit one in your IDE.

I did not succeed in building working 32 bit libraries using the TDM64-GCC 32-bit mode, which also seems to be reported as buggy elsewhere, so have concluded that it is best to use the compiler that comes built-in with Code::Blocks (or download the specific 32 bit compiler) for 32 bit builds, and use the tdm-gcc-64 compiler only for 64 bit builds.

I used this build method for the 32 and 64 bit versions of my app BackupCat as described in this thread: viewtopic.php?f=10&t=42768

References:

Compile wxWidgets 2.9.3 both 32/64 bit targets with MinGW
viewtopic.php?t=34980

Libs wxWidgets-2.9.3 compilées
http://www.wxdev.fr/topic683-Libs_wxWid ... ilees.html

Compiling wxWidgets with MinGW
https://wiki.wxwidgets.org/Compiling_wx ... with_MinGW

Post Reply