Yolinux.com Tutorial

Linux C++ Software Development

Links to Linux C++ GUI frameworks, APIs, IDEs, as well as C++ tips for Linux developers.


Table of Contents: YoLinux C++ and related Tutorials:


YoLinux Tutorials:

°YoLinux Tutorials Index



Free Information Technology Magazine Subscriptions and Document Downloads


Free Information Technology Software and Development Magazine Subscriptions and Document Downloads


C++ GUI Framework Toolkits:

Cross platform (Linux, MS/Windows, IRIX, Solaris (Gnome will be standard on Solaris 10))

GUI Framework links:


C++ Graphic Componets and Widgets:

  • SL.com - Sherrill - Lubinski SL-GMS
    Dynamic graphic GUI components and controls for real time interfaces and displays. Common ".m1" file graphic framework for C++ and Java. Graphic sources include Visio, bitmaps and DXF. Supports pan, zoom, drill-down and hyperlink capability. Supports input as well as displays.
  • Kinesix.com: Sammi - Similar to SL-GMS but not as good.
  • Genlogic.com: GLG - Dynamic, data driven visual components.
  • INT.com
  • ILog.com: Views - Diagraming and data graphing capabilities.


C++ Web Server CGI Toolkits:


Software Testing Tools:

  • CppUnit C++ port of IBM's JAva JUnit test framework. Test report output is in XML or text.
  • CxxTest - C++ test framework
  • Unit++ - testing library and framework


C/C++ Development environment for Linux:

The following tools will provide the infrastructure for a C++ on Linux development environment:
(Eclipse IDE, SCM and the build tools are cross platform and can be duplicated on MS/Windows and other UNIX environemnts)

  • IDE (Integrated Development Environment): Eclipse
    Download http://eclipse.org/downloads/ - i.e. eclipse-SDK-3.1.1-linux-gtk-x86_64.tar.gz
    Eclipse also requires the Java installation. See YoLinux Java download/installation

    Install Eclipse:

    • for all on system:
      • mv eclipse-SDK-3.1.1-linux-gtk-x86_64.tar.gz /opt
      • tar xzf eclipse-SDK-3.1.1-linux-gtk-x86_64.tar.gz
      This installs Eclipse under /opt/eclipse
      OR
    • for yourself only:
      • Download to your home directory.
      • tar xzf eclipse-SDK-3.1.1-linux-gtk-x86_64.tar.gz
      This installs Eclipse under /home/your-user-id/eclipse

    Be sure to include the following Eclipse plug-ins:

    • CDT: C/C++ development plug-in for Eclipse - [CDT manual]
      Install CDT plug-in:
      • Install from web: In Eclipse select "Help" from the menu bar + "Software Updates" + "Find and Install" + "Search for new features to install" + "Next" + "New Remote Site" to add an update site with the URL:
        http://download.eclipse.org/tools/cdt/releases/eclipse3.1
        OR
      • Download and install "tar.gz" file: http://download.eclipse.org/
        • download appropriate tar bundle for your platform: i.e. org.eclipse.cdt-3.0.0-linux.x86_64.tar.gz
          to the parent of the eclipse directory: i.e. /opt
        • tar xzf org.eclipse.cdt-3.0.0-linux.x86_64.tar.gz
          (To view contents of tar file: tar tzf org.eclipse.cdt-3.0.0-linux.x86_64.tar.gz)
      Verify installation: "Help" + "About Eclipse SDK" + "Plug-in Details". "C/C++ Development Tools" should be listed.
      Note that CDT is NOT platform independant. You must download and install the plug-in compiled for your platform. Eclipse "Help" menu will include tutorials on CDT after plug-in installation. Also See "Help" + "Welcome" + select "CDT Tutorials".

    • Subclipse: Subversion plug-in for Eclipse
      Installation:
      • Download site.0.9.36.zip to Eclipse directory: /opt/eclipse
      • Unzip file (May require installation of RPM package unzip): unzip site.0.9.36.zip
      • Start Eclipse IDE: /opt/eclipse/eclipse &
      • In Eclipse select: "Help" (from menu bar) + "Software Updates" + "Find and Install" (wait a minute or so for it to respond. No joke, on slow systems expect to wait over 3 min.) + "Search for new features to install" + "Next" + "New local site".
        Browse to: /opt/eclipse/update/ + select "OK"
      • Select the box next to "eclipse/update" + "Next" + select the "I accept the terms ..." + "Next" + Features to install: select "Subclipse 0.9.36" + "Finish" + "Install All" + "Yes" to restart Eclipse.
      • Select "Window" from the menu bar + "Open Perspective", select "Other...", select "SVN Repository Exploring", select "OK"
      Buttons on top right of Eclipse window can change back and forth from the IDE to Subversion browsing, or select "Window" from the menu bar + "Open Perspective" + "Other" + "SVN Repository Exploring" and then click "Ok".

      To add a new SVN repository: Right click in "SVN Repository" Exploring pane + right click "New", "Repository Location". In the "Add SVN Repository" window enter in the "Url:" space under "Location" the SVN location + select "Finish".

    • Subversive: Another Subversion plug-in for Eclipse. Includes more details for advanced Subversion users. Displays lots of version info. Annoying if you want a clean simple interface.
    • EHEP: Hex file viewer plug-in
    • VI plug-in - For those who love VI editing and cursor manipulation key bindings.
    • Prc-Eclipse - Palm OS development plug-in
    • CCA: C source code security analyzer plug-in

    [Potential Pitfall]: If Eclipse is installed in /opt/eclipse/ for system wide use, you may want to start Eclipse with the following command:

    eclipse -data /home/user1/workspace

    [Potential Pitfall]: When downloading Eclipse and Eclipse plug-ins, look at the README files (eclipse/readme/readme_eclipse.html) to see if you have a matching GTK+ release. If the version of Eclipse and plug-ins are too new for the version of GTK+ on your system then Eclipse may not display properly. For older versions of Linux, you may have to install older versions of Eclipse and older plug-ins. i.e. the latest version of Eclipse (3.1.1) on the older Red Hat Linux 8.0 will NOT operate properly. Eclipse 3.1.1 requires GTK 2.2.1 while Red Hat 8.0 uses GTK 2.0.

    [Potential Pitfall]: Don't mix 32 bit Java with 64 bit (AMD64/EM64T) Eclipse. Choose all 32 or all 64 bit for Eclipse environment.
    Error in ~/workspace/.metadata/.log

    !SESSION 2005-10-31 00:19:28.817 -----------------------------------------------eclipse.buildId=M20050929-0840
    java.version=1.4.2_09
    java.vendor=Sun Microsystems Inc.
    BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
    Command-line arguments: -os linux -ws gtk -arch x86_64

    !ENTRY org.eclipse.osgi 2005-10-31 00:19:29.787
    !MESSAGE Application error
    !STACK 1
    java.lang.UnsatisfiedLinkError: /opt/eclipse/configuration/org.eclipse.osgi/bundles/24/1/.cp/libswt-pi-gtk-3139.so:
    ...xxxxxxxxxxx...: cannot open shared object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1586)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1495)
    at java.lang.Runtime.loadLibrary0(Runtime.java:788)
    at java.lang.System.loadLibrary(System.java:834)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:123)
    at org.eclipse.swt.internal.gtk.OS.(OS.java:19)
    at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:63)
    at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:54)
    at org.eclipse.swt.widgets.Display.(Display.java:122)
    at org.eclipse.ui.internal.Workbench.createDisplay(Workbench.java:381)
    at org.eclipse.ui.PlatformUI.createDisplay(PlatformUI.java:155)
    at org.eclipse.ui.internal.ide.IDEApplication.createDisplay(IDEApplication.java:128)
    at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:79)
    at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:226)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
    at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
    at org.eclipse.core.launcher.Main.run(Main.java:973)
    at org.eclipse.core.launcher.Main.main(Main.java:948)
    Installing the RPM jdk-1_5_0_05-linux-amd64.rpm instead of the i586 version of Java to run with the x86_64 version of Eclipse fixes this problem.
    Notes:
    • Help/Welcome screen is default upon start-up and gives an introduction and tutorials on Eclipse . You can later return to this menu: "Help" + "Welcome".
    • I could not find any way to enter gdb debugger commands. The only input accepted is through the GUI. While it offers similar capability to MS/VC++, hard core debugging is best left to ddd.

  • Alternate C/C++ IDE: I can also recomend the Anjuta IDE for C/C++ development. Solid, simple, intuitive, bug free IDE for C/C++ development on Linux. Search/Indexing, edit, compile and debug.
    Packages:
    • YUM: yum install anjuta
    • RPMs available from Dag Wieers: Anjuta.
    • Ubuntu/Debian: apt-get install anjuta (requires: anjuta-common, libgtk2.0-dev libgtkmm2.0-dev libgnome2-dev libgnomemm2.0-dev devhelp-books glade-2 glade-gnome-2 cvs automake autogen indent ctags devhelp gnome-devel libtool)

  • SCM (Software Configuration Management):

  • Bug / issue tracking:

  • Build systems:
    • GNU gmake/make: GNU make is a build system based on the original UNIX "make" build system but with more features. Install RPM package: make
      GNU make manual
    • scons: Newer python based, cross platform build system. Great for cross platform development (i.e. MS/Windows and Linux/Unix)

  • Automated Nightly/Continuous Build and reporting systems:

  • File Compare Tools:
    • gtkdiff: Has diff3 and merge features. Written with GTK+. After gtkdiff-0.8.0, GNOME required.
    • fldiff: Graphical file and directory diff. (Cross platform)
    • kdiff3: Graphical directory and file diff, merge and edit. KDE3/Qt based. Supports drag and drop. Comes with S.u.S.E. distro. (Cross platform) MS/Windows download available.
      • Difference: kdiff file1 file2
      • Difference: kdiff file1 file2 file3
      • Difference of two files: kdiff directory1/file directory2
      • Difference: kdiff directory1 directory2
      • Merge: kdiff directory1 directory2 -o dest-directory
      • Merge: kdiff file1 file2 -m
      • Merge: kdiff file1 file2 -o output-file
    • Kompare: Ships with KDE SDK. [manual]
    • Meld: Compare, edit and merge.
    • mgdiff: [download] Motif-based graphical file difference browser and merge. Comes with S.u.S.E. distro.
    • tkdiff: [download]
    • gvim and gvimdiff
    • dirdiff: Directory difference viewer.

  • Compiler: Install RPM packages for GNU compiler gcc, gcc-c++, binutils (linker), glibc, glibc-devel, gdb

Note:


Configure fresh Linux installation for C/C++ development (gcc/g++):

If not pre-configured for software development, the following packages will have to be installed (at a minimum):

  • Ubuntu: sudo apt-get install gcc g++ make autoconf automake gawk
  • Red Hat: yum install gcc gcc-c++ make autoconf automake gawk binutils


Coding for cross platform deployment with gcc/g++:

The gcc/g++ compiler is compiled with a number of defined preprocessor variables. The list of defined variables compiled into gcc/g++ can be viewed by issuing the command: g++ -dumpspecs

The defined preprocessor variables can then be used to handle platform dependencies.

Platform Platform Variable Name Variable: unix Variable: posix Variable: _POSIX_SOURCE Architecture variable
GCC: RHEL/Fedora Linux linux
__gnu_linux__
*
* __i386__
__x86_64__
Red Hat 8 Linux linux
__gnu_linux__
* * *
Suse 9.2 Linux linux
__gnu_linux__
*


Sun Solaris/SPARC sparc


__arch64
SGI IRIX/MIPS sgi *
_SGI_SOURCE mips
host_mips
Cygwin Win/Intel-32 __CYGWIN32
WIN32
*
* _X86_

Example C/C++ source code 1:

#ifdef sparc
...
#endif
#ifdef linux
...
#endif
#ifdef __CYGWIN32
...
#endif
...
#if defined(linux) || defined(sparc)
...
#endif
...
Example C/C++ source code 2:
#ifdef sgi
return fn_sgi();
#elif defined(__CYGWIN32)
return fn_win();
#elif defined(linux)
return fn_linux();
#else
struct time ts;
return fn_time();
#endif
...
OR
#ifdef sgi
#include file_sgi.h
#elif defined(sparc)
#include file_sparc.h
#elif defined(linux)
#include file_linux.h
#else
#error Unknown OS type
#endif
...

Note use of the "#error" for error processing.

Also see YoLinux GNU Makefile cross platform tips


Notes:

  • Link error solution:
    If you get a similar error ClassName::ClassName[not-in-charge]
    The solution is to change the order of the libraries.
    i.e. If the following compile results in an error:
    g++ source-file.cpp -lxxx -lyyy -lzzz -L../XXX -L../YYY -L../ZZZ
    The solution is to change the order of the libraries:
    g++ source-file.cpp -lyyy -lzzz -lxxx -L../XXX -L../YYY -L../ZZZ
    The order of the library paths is irrellevant (-L).

  • C++ Link error: "undefined reference to `vtable for classname-goes-here`"
    My fix was to define a destructor. The virtual base class and destructor required the derived class to define a destructor.

  • Architecture independent data types and pointers:
    • Avoid 32/64 bit cross platform issues by using pointer type: intptr_t
      Use include file stdint.h. MS/Windows uses INT_PTR.
    • Avoid integer word size issues by using defined types in stdint.h
    • Libraries are typically found in /usr/lib and /lib. On systems which mix 32 and 64 bit libraries look for /usr/lib64 and /lib64.


Links:


Books:

C++ How to Program
by Harvey M. Deitel, Paul J. Deitel
ISBN #0131857576, Prentice Hall

Fifth edition. The first edition of this book (and Professor Sheely at UTA) taught me to program C++. It is complete and covers all the nuances of the C++ language. It also has good code examples. Good for both learning and reference.

Amazon.com
Exceptional C++: 47 Engineering Puzzles, Programming Problems and Solutions
by Herb Sutter
ISBN #0201615622, Addison-Wesley Professional

Advanced C++ features and STL.

Amazon.com
More Exceptional C++
by Herb Sutter
ISBN #020170434X, Addison-Wesley Professional

Amazon.com
Effective C++: 50 Specific Ways to Improve Your Programs and Design (2nd Edition)
by Scott Meyers
ISBN #0201924889, Addison-Wesley Professional

Amazon.com
More Effective C++: 35 New Ways to improve your Programs and Designs
by Scott Meyers
ISBN #020163371X, Addison-Wesley Professional

Amazon.com
Dr. Dobb's Journal

Free subscription to the premier resource for professional programmers and software developers. Multi-language and multi-platform with program listings, coding tips, design issue discussions and algorithms. Subscribe here!

Free
Subscription

See http://YoLinux.com for more Linux information and tutorials
Return to YoLinux Tutorial Index

Feedback Form
Copyright © 2001, 2002, 2003, 2005, 2006, 2007 by Greg Ippolito