June 10, 2013


(C++) wxWidgets and Code::Blocks


Some time ago I start interested in developing cross-platform GUI applications.
For developing this type of software uses such approaches as Java, GTK library,
Qt and as well scripting languages.

Any programmer thought that it would be great to write applications that will
run on Windows, Linux, MacOS, FreeBSD and without any patches and improvements.

I thinking of universal means to rapidly create cross-platform GUI applications,
and giving smart pointers, Unicode, regular expression, internationalization,
and so on.

For the realization of these objectives


1. Some words about why wxWidgets library.

For example QT library allows you to quickly create cross-platform GUI applications,
but criticized for the high consumption of resources and the large size of created
applications.

GTK-applications compiled for Windows, are also weigh a lot (in static linking),
or require prior installation GTK libraries (with dynamic linking).
It also uses a "non-native" elements management. So the GUI application written
in GTK for Windows looks a bit like alien.
You may find this inconsequential, but the average user of the button with rounded
corners instead usual sharp corners gets instant communication gap with a reality.

Around the Java situation, it is known that a Java application
running in 1,5 - 2 times slower than C++ applications.

Python/Ruby scripting languages have been rejected due to problems of portability
(Windows users are forced to download and install interpreters) and low productivity.

So what opportunities wxWidgets and Code::Blocks will gives us?

wxWidgets - it is a framework (library or we can say a set of classes)
to create cross-platform applications.
Something like STL + Boost + GTK in one.
Official site: http://www.wxwidgets.org/

Code::Blocks - a cross-platform RAD-IDE, sharpened for createion of applications
using C++ and wxWidgets.
Of the features of Code::Blocks is plugin support, a built-in
user interface editor (Plug wxSmith), as well as the ability to run IDE on
any operating system.
Official site: http://www.codeblocks.org/

What gives us the wxWidgets?
  • Portability applications for most modern operating systems without any changes;
  • Quickly create GUI, it uses native controls;
  • Smart pointers, threads are cross-platform, regular expressions, hashing, serialization, Unicode and internationalization, many other goodies, including
  • HTTP-and FTP-client, Parser XML, classes for working with databases and even
  • HTTP-ready server;
  • absence the need to preset JVM, interpreter, etc., relatively small size of the compiled applications that moderate consumption of memory and CPU cycles;
  • Possibility all used not only in the C++, but in Python, Ruby, Perl, Haskell, Erlang and other languages;

"Uses native controls" means that when compiling for Windows application will
draw a GUI with WinAPI, and when compiling under UNIX - using GTK or
if we want it, even in pure X11.

There is also the possibility of developing in wxWidgets mobile applications.

wxWidgets has and its drawbacks.
For example, when you declare a string to use either a macro _T (), or _().
First - just for strings in Unicode, the second - for internationalization.
This is somewhat annoying and slows encoding speed.
Fortunately, Code::Blocks can automatically substitute the pair
parentheses and quotation marks, so that our efforts minimized.

Another bad point - the small number of thematic blogs, video tutorials and
the almost complete lack of literature.
Fortunately, wxWidgets very easy to learn, and on official site provides
the full run background information.
There is a nice wiki article that fully describe WxWidgets comparing to other similar toolkits  WxWidgets Compared To Other Toolkits

2. Installing wxWidgets and Code::Blocks

Since we are dealing with cross-platform development, it all depends on OS we're using.
On Windows, you need to download:
Install wxPack, then MinGW, then Code::Blocks.
Utility wx-config.exe copy in «C:\Windows\» or wherever you have your Windows.

As it turned out, we can deliver and more recent version of MinGW, say,
if you want to use in your project capabilities C++0x.
Even wxPack not needed, it is enough to install a package wxMSW.

Just keep in mind that in some places in wxWidgets are used GCC extensions,
not included in the standard C++0x, so the
Project-> Build Options-> Compiler Settings-> Other Options append flag «-std=gnu++0x».
Flag «-std=c++0x», which Code::Blocks allows you to set a check mark in the next tab
Compiler Flags, will not works propertly in this case.

In Ubuntu/Debian installation is as follows:
sudo apt-get install codeblocks codeblocks-contrib g++
# about libwxgtk2.6-dev in doubt, first try without
sudo apt-get install wx2.8-headers libwxgtk2.8-0 \
libwxgtk2.8-dev libwxgtk2.6-dev
sudo ln -s /usr/include/wx-2.8/wx /usr/include/wx
# if there is no file /usr/include/wx/setup.h then write
sudo ln -s /usr/include/wx-2.6/wx/deprecated/setup.h \ 
/usr/include/wx/setup.h
Verification:
wx-config --cxxflags 
wx-config --libs
Installing FreeBSD's a lot easier for all of the dependencies are drawn automatically:
pkg_add-r codeblocks
Start the IDE, go to the menu «Settings> Compiler and debugger ...».
In «Compiler Sittings-> Other Options» write:`
'wxgtk2u-2.8-config --cppflags'
In «Linker Settings-> Other linker options» prescribes:
'wxgtk2u-2.8-config --libs'
In case of any problems with a probability of 90% solution would be to prescribing
right ways to setup Code::Blocks or editing environment variables.
When porting a project from *nix into Windows, you need to make sure that the
«Project-> Build Options-> Compiler/Linker Settings» wx-config is called with the «--static=yes».