Introduction
Download sample binary
Download source code
This article shows you how to setup wxWidgets under Microsoft Windows. In the next section I'll present you the advantages for using wxWidgets. I'll describe you what options should be set for the configuration and compilation process and what they mean in detail.
Why use wxWidgets?
wxWidgets is a toolkit that enables you to
- write rich GUI interfaces for platforms like Linux derivatives, Windows, and Mac OS X.
- write code once and recompile
it for a new platform, there's nearly no need to rewrite code or adopt code for specific platforms, it is even possible to cross compile code.
- Whenever possible, wxWidgets uses the native platform SDK and system provided widgets. This means that a program compiled on Windows will have the look and feel of a Windows program,
and when compiled on a Linux machine, it will get the look and feel of a Linux program.
- sell applications commercially. Basically wxWidgets
is L-GPL.
- use any language other than C++, there are various bindings for Python, Perl, PHP, Java, lua, LISP, Erlang, Eiffel,
.NET (e.g., C#, VB.NET, or Managed C++), BASIC, Ruby, and even JavaScript.
- use more than just the GUI classes, it is even possible to use wxWidgets for networking
or to interact with OpenGL.
- get tons of material on how to program GUIs.
Why not use wxWidgets?
- wxWidgets doesn't provide binaries.
- If you want to write programs with wxWidgets you need to compile it yourself or depend on a third party that has already compiled
wxWidgets for you and your target platform.
1. First things first ...
Navigate to the download section of the wxWidgets' homepage or try to find the homepage
in you favorite search engine.
Download either the zip file or the exe installer for wxMSW. It is important that you choose a windows compatible version, because the header files have
been adapted for each environment.
Now extract the recently downloaded ZIP file or let the wizard guide you through the installer.
I've chosen c:\wx as the root directory, but in fact the location is up to you. To create a directory under the Windows systems greater or equal
to Windows Vista in the root of your system drive you need to run your command shell in an elevated mode (i.e. as an administrator) - otherwise it won't work for you.
After the directory has been created, grant you user full control to that directory:
Now extract your archive to that directory.
2. Installing MinGW and MSYS
Once again, you'll need your browser application ...
Navigate to the SourceForge MinGW project and download a file like
mingw-get-inst-DATE.exe
In my case I downloaded "mingw-get-inst-20120426.exe".
Start the wizard and navigate through it ...
Select C, C++, MSYS and the MinGW Developer ToolKit (Selecting the developer toolkit is not needed and can be considered as an optional task):
Ensure that MinGW will be installed in the root of your system drive. In that case you'll have no problems with navigation and paths.
Now navigate to
C:\mingw\msys\1.0
and double-click the msys.bat file.
This ensures that you home folder will be created. You are now ready to proceed to the next phase. The configuration and compilation.
Configuration and Compilation
Open MSYS. Navigate to
cd c:/wx/
Attention ... Note, that we are in a Unix shell and need to use slashes (/) for directory navigation instead of backslashes (\).
Now create the build folder and navigate into it ...
mkdir msw-debug
cd msw-debug
Now configure wxWidgets. The configuration step is quite important. Calling the configure script creates the make files and sets system-dependent variables.
../configure --build=x86-winnt-mingw32 --disable-shared --disable-threads
As you can see above in the screenshot, the configuration script currently creates the makefiles for the samples we'll use later.
Let's start the actual build process by calling
make MONOLITHIC=1 SHARED=0 UNICODE=1 BUILD=release DEBUG_FLAG=0
- MONOLITHIC=1 ... Packages all libraries in a single file.
- SHARED=0 ... We want to create static libraries instead of DLLs (dynamically linked ones)
- BUILD=release & DEBUG_FLAG=0 ... we don't want to include debugging information in our resulting binaries (i.e. the static library)
- UNICODE=1 ... we want to use Unicode instead of a specific culture or locale.
Installation:
make install
Testing
Compile a source code sample. We'll use the skeleton
cd samples/minimal; make && minimal.exe && cd ../..
Now navigate with your Windows Explorer to
C:\wx\msw-debug\samples\minimal
Congrats! You have successfully set up wxWidgets for Windows!
Compilation remarks
In case writing make files or having make files at your fingertips is not always possible, it is totally fine to invoke g++ directly by issuing a command line like
g++ *.cpp *.h `wx-config --cxxflags --libs` -o Test
or
g++ `wx-config --cxxflags` -o out *.cpp `wx-config --libs`
BTW: Please ensure that you are using `backticks` instead of the 'inverted comma' as shown above. Using backticks (`) is highly important; otherwise the compilation will fail.
More details can be found here:
http://wiki.wxwidgets.org/Wx-Config