wxWidgets: Compilation and Installation

After migrating my projects to Qt, I discontinued building wx devpaks. This guide will help you to compile your own wxWidgets libs of the latest sources.

Compile wxWidgets

This compilation guide shows how to build a static wxWidgets lib. Once you get this working you will have no issues configuring the lib to you needs. It is required to install gcc 3.x for Windows, and the bin directory of gcc needs to be added to the PATH system variable.
The easiest way to obtain gcc is installing Cygwin. Run the installer and choose the compiler packages for download.
The Cygwin setup will also install bash, make and autotools, which are required to build wxWidgets. If you already have gcc, but no shell, take a look at MSYS.

Get the wxAll source package at wxwidgets.org: Link to 2.8.10 stable

Unpack the tarball, the following assumes that the directory wx contains its content.

Open your shell and change to the new wx directory.

Type mkdir static && cd static

Type ../configure -q --with-msw --disable-debug --disable-debug_gdb --disable-shared --enable-stl --with-opengl --enable-compat26 --enable-std_string --enable-std_iostreams

The configure script will output:
loading argument cache configarg.cache
saving argument cache configarg.cache
configure: WARNING: system regex library not found, will use built-in instead
configure: WARNING: zlib library not found or too old, will use built-in instead
configure: WARNING: system png library not found or too old, will use built-in instead
configure: WARNING: system jpeg library not found, will use built-in instead
configure: WARNING: system tiff library not found, will use built-in instead
configure: WARNING: system expat library not found, will use built-in instead
configure: WARNING: Catching fatal exceptions not currently supported on this system, wxApp::OnFatalException will not be called
../configure: eval: line 1: unexpected EOF while looking for matching `"'
../configure: eval: line 2: syntax error: unexpected end of file
checking for gcc... gcc
[...]
configure: creating ./config.status
config.status: creating Makefile
config.status: creating expat_config.h

Configured wxWidgets 2.8.10 for `i686-pc-mingw32'

  Which GUI toolkit should wxWidgets use?                 msw
  Should wxWidgets be compiled into single library?       no
  Should wxWidgets be compiled in debug mode?             no
  Should wxWidgets be linked as a shared library?         no
  Should wxWidgets be compiled in Unicode mode?           no
  What level of wxWidgets compatibility should be enabled?
                                       wxWidgets 2.4      no
                                       wxWidgets 2.6      yes
  Which libraries should wxWidgets use?
                                       jpeg               builtin
                                       png                builtin
                                       regex              builtin
                                       tiff               builtin
                                       zlib               builtin
                                       odbc               no
                                       expat              builtin
                                       libmspack          no
                                       sdl                no
This is my setup which provides good STL compatibility and reasonable file size. Type ../configure -h to see all available options.

Type make

The output might look like an error message:
/f/wxWidgets/wxWidgets-2.8.10/wxWidgets-2.8.10/static/bk-deps gcc -c -o wxregex_regcomp.o -D__WXMSW__   -I/f/wxWidgets/wxWidgets-2.8.10/wxWidgets-2.8.10/static/lib/wx/include/msw-ansi-release-static-2.8 -I../include -mthreads -Wall -Wundef -O2 -fno-strict-aliasing -mthreads ../src/regex/regcomp.c
process_begin: CreateProcess((null), /f/wxWidgets/wxWidgets-2.8.10/wxWidgets-2.8.10/static/bk-deps gcc -c -o wxregex_regcomp.o -D__WXMSW__ -I/f/wxWidgets/wxWidgets-2.8.10/wxWidgets-2.8.10/static/lib/wx/include/msw-ansi-release-static-2.8 -I../include -mthreads -Wall -Wundef -O2 -fno-strict-aliasing -mthreads ../src/regex/regcomp.c, ...) failed.
make (e=3): The system cannot find the given path.
Don't panic, open static/Makefile and look for the absolute paths assigned to the variables BK_DEPS, BK_MAKE_PCH and wx_top_builddir.
Replace them by the following values:

BK_DEPS = ./bk-deps
BK_MAKE_PCH = ./bk-make-pch
wx_top_builddir=.

If you need the wxrc program, open static/utils/wxrc/Makefile and set the BK_DEPS and wx_top_builddir variables as shown below:

BK_DEPS = ../../bk-deps
wx_top_builddir = ../..

Type make

Now wxWidgets should compile. You can delete the *.o files afterwards.
The libraries will be found in the static/lib directory. To use the libs in your projects, set the include and lib paths of your project as described below.

Using the Devpaks

The wxWidgets devpaks contains static libraries of the WxWidgets stable release.
Unicode and debugging support was disabled for 2.8.x to provide a small file size, while ODBC and OpenGL support was enabled.
Unicode is enabled for 2.9.x nightly builds. See wxwidgets changelog if you want to use 2.9.x nightly builds.

Requirements

You need to install gcc 3.4.2 (included in Bloodshed DevCpp 4.9.9.2).
Although devpak is the software packaging format designed for DevCpp, you can use the contained libraries within an existing MinGW installation or with Code::Blocks, too: Rename the devpak file to tar.bz2, and unpack its content to a suitable location.

If for some reason the Dev-Cpp Packman tool fails, you can still unpack the tar.bz2 file and double click the DevPackage file to install the content of the unpacked directory.

Sometimes Packman does not properly decompress the archive. I have experienced that the subdirectories and include files in the lib/wx/include/msw-ansi-release-static-2.x/ directory are missing after installing the devpak file. Please check that there is a /wx directory, which includes a setup.h file. This header file is important as it contains the compiler settings which were defined before compilation of the libs. If this file is missing, please unpack the devpak as described above.

Devpak Content

Project Settings

You have to add some include and library paths to your DevCpp (or Code::Blocks ) project settings before compiling your wxWidgets project:

  1. Open "Project-> Project Options-> Directories"
  2. In the Library Directories section, add
    "<Dev-Cpp-Root>\wxWidgets-2.8.X-msw-static\lib"
  3. In the Include Directories section, add
    "<Dev-Cpp-Root>\wxWidgets-2.8.X-msw-static\include"
    "<Dev-Cpp-Root>\wxWidgets-2.8.X-msw-static\lib\wx\include\msw-ansi-release-static-2.8"
  4. If you need the wx resource files, click Resource directories and add
    "<Dev-Cpp-Root>\wxWidgets-2.8.X-msw-static\include"

where <Dev-Cpp-Root> is your Dev-Cpp installation directory (like E:\Dev-Cpp). Replace the placeholder X by the current minor version number.
If you use more libraries (for example a wxWidgets contribution), you have to add the library and include paths accordingly.

Compiler and Linker settings

These flags have to be applied to gcc when compiling programs using the wxWidgets libraries (Project-> Project Options-> Parameters):

C++ Compiler flags:
-D__WXMSW__ -DNO_GCC_PRAGMA

Linker flags:
-s -mwindows -lwx_msw_core-2.8 -lwx_base-2.8 -lwxjpeg-2.8 -lwxpng-2.8 -lwxzlib-2.8
-lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32
-lcomdlg32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi32 -ltiff

These flags contain the most important libraries. Order is important.
Additional libraries have to be added to this string (Example: add -lwx_msw_adv-2.8 if you want to use the WxWizard classes).

You should use mingw32-make to compile your projects.

WxWidgets 2.8.x compilation

The libraries were compiled with the following settings:

../configure -q --with-msw --disable-debug --disable-debug_gdb --disable-shared
   --disable-compat24 --with-odbc --with-opengl

Configured wxWidgets 2.8.9 for `i686-pc-mingw32'

  Which GUI toolkit should wxWidgets use?                 msw
  Should wxWidgets be compiled into single library?       no
  Should wxWidgets be compiled in debug mode?             no
  Should wxWidgets be linked as a shared library?         no
  Should wxWidgets be compiled in Unicode mode?           no
  What level of wxWidgets compatibility should be enabled?
                                       wxWidgets 2.4      no
                                       wxWidgets 2.6      yes
  Which libraries should wxWidgets use?
                                       jpeg               builtin
                                       png                builtin
                                       regex              builtin
                                       tiff               builtin
                                       zlib               builtin
                                       odbc               no
                                       expat              builtin
                                       libmspack          no
                                       sdl                no

WxWidgets 2.9.0 compilation

The libraries were compiled with the following settings:

../configure -q --with-msw --disable-debug --disable-debug_gdb --disable-shared
   --enable-stl  --with-opengl  --enable-compat26 --enable-std_string --enable-std_iostreams

Completed: At revision: 57404  

Libtiff is now configured for i686-pc-mingw32

  Installation directory:             /usr/local
  Documentation directory:            ${prefix}/share/doc/tiff-3.8.2
  C compiler:                         gcc -g -O2 -Wall -W
  C++ compiler:                       g++ -g -O2
  Enable runtime linker paths:        no
  Support Microsoft Document Imaging: yes

 Support for internal codecs:
  CCITT Group 3 & 4 algorithms:       yes
  Macintosh PackBits algorithm:       yes
  LZW algorithm:                      yes
  ThunderScan 4-bit RLE algorithm:    yes
  NeXT 2-bit RLE algorithm:           yes
  LogLuv high dynamic range encoding: yes

 Support for external codecs:
  ZLIB support:                       no
  Pixar log-format algorithm:         no
  JPEG support:                       no
  Old JPEG support:                   no
  C++ support:                        yes
  OpenGL support:                     no

creating libtool

Configured wxWidgets 2.9.0 for `i686-pc-mingw32'

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

Download DevPak...