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 »

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
acer_bob
In need of some credit
In need of some credit
Posts: 1
Joined: Wed May 27, 2020 10:23 am

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

Post by acer_bob »

Seems i found a bug that does not allow building 32-bit wxWidgets on a 64-bit machine. In the include\wx\msw\genrcdefs.h file, the line #if defined _M_AMD64 || defined __x86_64__ falsely identifies a 64-bit processor.
You need to remove "|| defined __x86_64__" and leave only #if defined _M_AMD64 and run something like:

path C:\TDM-GCC-64\bin;$WXWIN/include;
mingw32-make -I "c:\wxWidgets-3.0.5\lib\gcc_dll-x86\mswu" -j8 -f makefile.gcc CFG=-x86 BUILD=release SHARED=1 MONOLITHIC=0 CPP="CPP -D_X86_" CXXFLAGS="-m32" CPPFLAGS="-m32" LDFLAGS="-m32" WINDRES="windres -F pe-i386 -D_X86_"

сodeblocks settings:
compiler flags -> target x86 (32bit) [-m32]
other resource compiler options -> -D__i386__ -F pe-i386
Last edited by acer_bob on Wed May 27, 2020 3:28 pm, edited 1 time in total.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

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

Post by PB »

acer_bob wrote: Wed May 27, 2020 11:05 amSeems i found a bug that does not allow building 32-bit wxWidgets on a 64-bit machine.
I am quite sure you have not. I have built 32-bit wxWidgets on 64-bit Windows with several compilers (both MSVC and GCC based) and configurations.

acer_bob wrote: Wed May 27, 2020 11:05 am In the include\wx\msw\genrcdefs.h file, the line #if defined _M_AMD64 || defined __x86_64__ falsely identifies a 64-bit processor.
Those defines are obviously not related to the CPU where the build is done. These are set as parameters of the build process. You must either be doing something wrong, or the compiler you are using is buggy.

BTW, you certainly do not need to add an include folder to the PATH, it makes no sense for it to be there.The include folder also does not belong to the command line when building wxWidgets with the provided gcc makefile (or any other way), where it can break things.

I have not used TDM-GCC in many years (see the C++ standard below), but I dug out some batch files, not sure they are totally correct (I think they were for TDM-GCC 5). Also please notice that when one uses GCC parallel build feature (-jN), one must build the setup_h target first, to avoid possible build error.

Code: Select all

mingw32-make -f makefile.gcc BUILD=release CPP="gcc -E -D_M_IX86 -m32" CFLAGS="-m32" CXXFLAGS="-m32 -std=gnu++11" CPPFLAGS="-m32" LDFLAGS="-m32" WINDRES="windres --use-temp-file -F pe-i386" setup_h

mingw32-make -j4 -f makefile.gcc BUILD=release CPP="gcc -E -D_M_IX86 -m32" CFLAGS="-m32" CXXFLAGS="-m32 -std=gnu++11" CPPFLAGS="-m32" LDFLAGS="-m32" WINDRES="windres --use-temp-file -F pe-i386"
Other GCC-based Windows compilers (such as minGW and mingw-64) seem to prefer having separate 32- and 64-bit distributions, each building for the respective architecture.
Post Reply