Click here to Skip to main content
Click here to Skip to main content

Introduction to wxWidgets - 2.

, 23 Feb 2006
Rate this:
Please Sign up or sign in to vote.
A beginner’s tutorial to wxWidgets on Linux.

Introduction

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.

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.

Getting Started

We will port our classic 'Hello World' 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 'devel' then open the terminal window and move to that folder and issue the following commands:
tar - xjvf wxGTK-2.6.2.tar.bz2
mkdir buildStaticGTK
cd buildStaticGTK
../configure --with-gtk -disable-shared
make
su <type root password>
make install
ldconfig
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:
wx-config --cxxflags
wxconfig --libs
These will display the settings of the wxWidgets for the C++ compiler. Note them down in case of any errors. Now copy the file 'hello.cpp' 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`
./hello
Congrats again! You have successfully compiled wxWidgets Hello World on Linux, if you have any problem, try to replace the `wx-config --cxxflags` and `wx-config --libs` with the output you get earlier on command promt, also note that the symbol around wx-config -cxxflags, is not inverted comma but apostrophe. If that works, just copy the wx-config link in the buildStaticGTK directory to the /usr/bin directory.

Click to enlarge!

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).
  • Type 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.

    Click to enlarge!

  • Change the author name and set the contact email address, you may also choose an appropriate license.

    Click to enlarge!

  • Change the license text to be displayed in the source files for '.h' and '.cpp' files if needed, and select finish.

    Click to enlarge!

  • This will create a simple wxWidgets application in the provided directory. Select OK.

    Click to enlarge!

  • 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 $(wx-config --libs).

    Click to enlarge!

  • In the 'Compiler flags (CXXFLAGS)' in 'C++' tab, change the value to $(wx-config --cxxflags).

    Click to enlarge!

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

    Click to enlarge!

  • Then from the 'Build' menu select 'Build Project'. It will ask to Run automake & friends and configure first. Select 'Yes'.

    Click to enlarge!

  • Wait for a minute, then from the 'Debug' menu select 'Start'. And you are finished with building wxWidgets applications with KDevelop for Linux.

    Click to enlarge!

  • Congrats! Now can modify the source files generated by the wizard and try experimenting. Happy Programming!Smile | :)

Special Thanks

  • Mahr - For his valuable guidance on getting started with Linux.
  • Dominik Reichl - For modifying the images clearity.

License

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

About the Author

Priyank Bolia
Software Developer (Senior)
India India
No Biography provided

Comments and Discussions

 
GeneralwxWidgets tutorial Pinmembervirgil_trasca2-Apr-08 11:36 
wxWidgets is a very good library. I want to share to the community some of my wxWidgets experience.
Here is a tutorial which I will update from time to time.
GeneralI have below Problem in Debug using KDevelop, wxWidgets PinmemberMember #393878519-Mar-07 19:14 
GeneralPlease ask all questions at http://wxforum.shadonet.com/ PinmemberPriyank Bolia19-Mar-07 20:10 
QuestionDo you have documents about porting wxWidgets to another os? Pinmemberchanglezhang17-Dec-06 2:03 
AnswerRe: Do you have documents about porting wxWidgets to another os? PinmemberPriyank Bolia17-Dec-06 17:54 
GeneralRe: Do you have documents about porting wxWidgets to another os? Pinmembergaurav1197914-Oct-07 21:31 
GeneralRe: Do you have documents about porting wxWidgets to another os? PinmemberPriyank Bolia14-Oct-07 21:52 
GeneralErrorettes! PinmemberKixdemp7-Mar-06 10:45 
Generalvery nice Pinmembermapopa23-Feb-06 4:45 
GeneralRe: very nice PinmemberPriyank Bolia23-Feb-06 19:01 
GeneralNow you have convinced me... PinmemberJohn A. Johnson11-Dec-05 23:43 
GeneralRe: Now you have convinced me... PinmemberPriyank Bolia11-Dec-05 23:56 
GeneralRe: Now you have convinced me... PinmemberJohn A. Johnson12-Dec-05 1:03 
GeneralRe: Now you have convinced me... PinmemberPriyank Bolia12-Dec-05 1:35 
JokeRe: Now you have convinced me... Pinmembertoxcct23-Feb-06 23:19 
QuestionUh? PinmemberSuper Lloyd10-Dec-05 23:07 
GeneralVery good... Pinmemberneotrace30-Nov-05 8:45 
GeneralI'm a bit surprised PinmemberT1TAN23-Oct-05 22:22 
GeneralRe: I'm a bit surprised PinmemberPriyank Bolia23-Oct-05 22:41 
GeneralRe: I'm a bit surprised PinmemberT1TAN24-Oct-05 2:07 
GeneralRe: I'm a bit surprised PinmemberPriyank Bolia24-Oct-05 2:10 
GeneralRe: I'm a bit surprised PinmemberT1TAN24-Oct-05 2:27 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 24 Feb 2006
Article Copyright 2005 by Priyank Bolia
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid