Welcome again, to the 'Introduction to wxWidgets - Part 2'. This article is an extension to the previous article: Introduction to wxWidgets
. You may like to visit that at: http://www.codeproject.com/library/wxwidgets.asp
before proceeding to this article. This article talks, about the left out section in the previous article, building application with wxWidgets on other platforms, which is the real power of wxWidgets. "Code once, Run anywhere with full performance and native look & feel". This article talks about working with wxWidgets on Linux.
Today Linux has joined the desktop market. There are more than 29 million Linux users on an average and thousands of distributions available. Linux developers concentrated on networking and services in the beginning, and office applications have been the last barrier to be taken down. Today with OpenOffice.org 2.0 goes gold, Firefox exceeding 100 million downloads in one year, ASF (Apache), Ubuntu projects and support for rich multimedia on Desktops, strong backup by IBM, HP, Sun, Novell, Sony, Red Hat, etc., Linux is attaining new limits in the industry.
On the server side, Linux is well-known as a stable and reliable platform, providing database and trading services for companies like Amazon, the well-known online bookshop, US Post Office, the German army and such. Especially Internet providers and Internet service providers have grown fond of Linux as firewall, proxy- and web server, and you will find a Linux box within reach of every UNIX system administrator who appreciates a comfortable management station. Clusters of Linux machines are used in the creation of movies such as “Titanic”, “Shrek” and others. In post offices, they are the nerve centers that route mail and in large search engine, clusters are used to perform internet searches. Call centers have a significant appetite for Linux, as does Government, Health Care and major manufacturing. These are only a few of the thousands of heavy-duty jobs that Linux is performing day-to-day across the world.
It is also worth to note that modern Linux not only runs on workstations, mid- and high-end servers, but also on “gadgets” like PDA's, mobiles, a shipload of embedded applications and even on experimental wristwatches. This makes Linux the only operating system in the world covering such a wide range of hardware.
We will port our classic '
' program to Linux environment in this article. Though I am not a master of Linux, so I can't answer all your queries, but I think the installation in Linux is much easier. I used Red Hat Linux with Fedora Core 3 and install a graphical workstation (X Window/GTK) with all the programming tools like GCC, KDevelop, Emacs, GEdit, etc. For installation of Linux you can refer to some good books or articles on internet; both are in plenty. After you have installed the Linux, test the installation by writing a C++ program in your favorite editor to make sure that everything is in place. Refer:
Now download the wxGTK-2.6.2
and copy it into a folder say '
' then open the terminal window and move to that folder and issue the following commands:
tar - xjvf wxGTK-2.6.2.tar.bz2
../configure --with-gtk -disable-shared
su <type root password>
I hope that much should proceed without any problems, if you face any problems, you can go to wxForum
and post you errors and don't forgot to read the INSTALL.txt in the wxWidgets directory where you had unpacked the wxGTK-2.6.2.tar.bz2 file. Now to test whether wxWidgets has installed successfully, in the terminal window, move to the same buildStaticGTK directory and issue the following command:
These will display the settings of the wxWidgets for the C++ compiler. Note them down in case of any errors. Now copy the file '
' to any directory and move to that directory in the terminal window and issue the following commands:
g++ -c `wx-config --cxxflags` hello.cpp
g++ -o hello hello.o `wx-config --libs`
You have successfully compiled wxWidgets Hello World on Linux, if you have any problem, try to replace the `
` and `
` with the output you get earlier on command promt, also note that the symbol around
, is not inverted comma but apostrophe. If that works, just copy the
link in the buildStaticGTK directory to the
In case of any problems, you can click on the above screenshot to enlarge and see what commands/syntax are given to the terminal.
wxWidgets with KDevelop:
This article will walk through the sequences to help you get started with wxWidgets on KDevelop (Linux).
kdevelop in the terminal and in the 'Project' Menu of KDevelop
select 'New Project...'. Select 'C++ >> wxWidgets >> Simple Hello wxWidgets application'. Choose an appropriate application name and location.
- Change the author name and set the contact email address, you may also choose an appropriate license.
- Change the license text to be displayed in the source files for '.h' and '.cpp' files if needed, and select finish.
- This will create a simple wxWidgets application in the provided directory. Select OK.
- Select 'Project Options...' from the 'Project' menu. Select 'Configure Options' in the left panel from the project options dialog box. In the 'Linker flags (LDFLAGS)' in 'General' tab write
- In the 'Compiler flags (CXXFLAGS)' in 'C++' tab, change the value to
- You may repeat the above two steps for linker and compiler flags for 'release' configuration also. Then select 'OK', and it will ask to Re-run configure for the project. Select 'Yes'.
- Then from the 'Build' menu select 'Build Project'. It will ask to Run automake & friends and configure first. Select 'Yes'.
- Wait for a minute, then from the 'Debug' menu select 'Start'. And you are finished with building wxWidgets applications with KDevelop for Linux.
- Congrats! Now can modify the source files generated by the wizard and try experimenting. Happy Programming!
- Mahr - For his valuable guidance on getting started with Linux.
- Dominik Reichl - For modifying the images clearity.