Click here to Skip to main content
15,867,594 members
Articles / Programming Languages / C++
Tip/Trick

Using wxWidgets under Windows

Rate me:
Please Sign up or sign in to vote.
4.82/5 (9 votes)
19 Aug 2013LGPL34 min read 48.8K   949   29   13
This is a small "how to" that shows you how to get wxWidgets running under Windows

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.

Image 1

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.

Image 2

Now extract the recently downloaded ZIP file or let the wizard guide you through the installer.

Image 3

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.

Image 4

After the directory has been created, grant you user full control to that directory:

Image 5

Now extract your archive to that directory.

Image 6

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 ...

Image 7

Select C, C++, MSYS and the MinGW Developer ToolKit (Selecting the developer toolkit is not needed and can be considered as an optional task):

Image 8

Image 9

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

Image 10

and double-click the msys.bat file.

Image 11

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

Image 12

Image 13

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.

Image 14

Installation:

make install

Image 15

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

Image 16

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

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Oliver Kohl D.Sc.
Austria Austria
https://www.conteco.gmbh

Comments and Discussions

 
QuestionCan I build static application with wxWidgets? Pin
AsfK21-Aug-13 0:09
AsfK21-Aug-13 0:09 
AnswerRe: Can I build static application with wxWidgets? Pin
Oliver Kohl21-Aug-13 4:15
Oliver Kohl21-Aug-13 4:15 
Yes, you can by using SHARED=0.

Setting SHARED to zero means that we don't want to depend on dynamically linked libraries instead we want to compile time link (embed) the resulting lib file.

This ensures that you neither need a runtime nor any files to execute the application, just the EXE file, the elf binary or the app file itself.

BTW: In your case I suggest to set MONOLITHIC to zero too. This ensures that you don't end up with a file of 2.5 MB for just a skeleton.
GeneralMy vote of 4 Pin
Amir Mohammad Nasrollahi20-Aug-13 6:20
professionalAmir Mohammad Nasrollahi20-Aug-13 6:20 
GeneralRe: My vote of 4 Pin
Oliver Kohl20-Aug-13 22:30
Oliver Kohl20-Aug-13 22:30 
AnswerIDE to work with wx Pin
xawari17-Aug-13 7:43
xawari17-Aug-13 7:43 
AnswerRe: IDE to work with wx Pin
Oliver Kohl19-Aug-13 21:21
Oliver Kohl19-Aug-13 21:21 
GeneralRe: IDE to work with wx Pin
glucato21-Aug-13 3:52
glucato21-Aug-13 3:52 
AnswerRe: IDE to work with wx Pin
Oliver Kohl21-Aug-13 4:17
Oliver Kohl21-Aug-13 4:17 
SuggestionMinGW settings Pin
Emilio Garavaglia15-Aug-13 21:40
Emilio Garavaglia15-Aug-13 21:40 
AnswerRe: MinGW settings Pin
Oliver Kohl19-Aug-13 21:23
Oliver Kohl19-Aug-13 21:23 
GeneralRe: MinGW settings Pin
Oliver Kohl19-Aug-13 21:57
Oliver Kohl19-Aug-13 21:57 
Questionprebuilt wx widgets Pin
Ivan Mladenović2-Aug-13 3:58
Ivan Mladenović2-Aug-13 3:58 
AnswerRe: prebuilt wx widgets Pin
Oliver Kohl3-Aug-13 1:24
Oliver Kohl3-Aug-13 1:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.