1. Home
  2. Tutorials
  3. C/C++
Yolinux.com Tutorial

Linux C++ Software Development

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

C++ GUI Programming Framework Toolkits:

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

C++ Graphic Components 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 - Diagramming and data graphing capabilities.

C++ Web Server CGI Toolkits:

Software Testing Tools:

C/C++ IDE (Integrated Development Environment) for Linux:

The following IDEs will provide an integrated edit, build and debugging environment for C++ on Linux.

(IDEs are cross platform and are available on MS/Windows and other UNIX environments)

Eclipse/CDT:

Written in Java, this IDE was originally developed for programming JAVA. Since its' inception, it was designed with a plug-in architecture to support other languages and programming needs. For C++ development, one must download the Eclipse CDT version for C++ which is platform dependent and processor word size dependent (32 bit/64 bit) and not the same download as the regular Java Eclipse IDE.

Eclipse Home Page
Download http://eclipse.org/downloads/ - i.e. eclipse-cpp-XXX-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-cpp-XXX-linux-gtk-x86_64.tar.gz /opt
    • tar xzf eclipse-cpp-XXX-linux-gtk-x86_64.tar.gz
    This installs Eclipse under /opt/eclipse
    OR
  • for yourself only:
    • Download to your home directory.
    • tar xzf eclipse-cpp-XXX-linux-gtk-x86_64.tar.gz
    This installs Eclipse under /home/your-user-id/eclipse
  • Run Eclipse:
    • /opt/eclipse/eclipse
    • Icon for desktop launcher: /opt/eclipse/icon.xpm
  • for all on system:
Also see: CDT manual

You may also want to include the following Eclipse plug-ins:

  • 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
  • Eclipse VI plug-in - For those who love VI editing and cursor manipulation key bindings.
  • List of Source Code Security Analyzers

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

NetBeans:

This Sun IDE has refactoring support, profiler integration, fantastic cross referencing and navigation support (not limited to ctags) with code completion. It supports Qt development, Linux GNU, Cygwin and MinGW C/C++ compilers and GDB debuggers. You can inspect the class inheritance hierarchy, a header's include hierarchy, the type hierarchy, and more. It supports GNU Makefiles and C++ as well as language support for Java/Ant, Javascript, Python, Ruby, Groovy and PHP. The only drawback I have experienced is running it remotely over the XMing MS/Windows X-server. NetBeans is probably the most feature-rich C++ IDE available for Linux.

Netbeans requires Java installations. See YoLinux Java download/installation

NetBeans for C++
NetBeans C/C++ tutorial

KDevelop:

KDevelop has built-in Qt GUI development support (KDesigner), dOxygen auto-documentation support, makefile, ctags based navigation. Subversion, CVS, Perforce and Clearcase CM client support is built-in.

KDevelop provides cross platform support for MS Windows, Mac OsX, Linux, Solaris and FreeBSD. It also supports multiple languages such as C/C++, PHP ad Ruby as well as Automake, Make, qMake, CMake and Ant build systems. This IDE works and is simple to use.

Quick start (using existing C++/Makefile code):
  • Start: kdevelop&
    or start from Linux menu under "Programming".
  • Top tool bar: Project + Import existing project ...
    • Directory: select for example ~/projectx/src
    • Project name: ProjectX
    • Project type: (default) Generic C++ Application (Custom Makefiles)
    • OK
    • Dialog box will ask if you want to populate with files recursively from the project directory: YES
    • Select "File Tree" from left side tab to view files. Use right mouse button to invoke Subversion commands (i.e. update, commit, add, remove, ...)
    • Generate CTAGS for file navigation: (navigate to function and variable declarations, etc)
      • Select "CTAGS" tab on bottom
      • Select "Regenerate" button
      • Build (uses your make file):
        Options:
        • Build project (will run makefile)
        • Build target:
          • cleanall
          • clean
          • all
          • componenta
          • componentb
          • ...

Debugging: (GUI front-end to GDB)

  • Top tool bar: Project + Project options...
    • Icon on left: Select "Run Options":
      • Directory: "Custom directory"
        Select: ~~~/projectx/rundir/
      • Program: ~~~/projectx/bin/Linux/program.exe
        Set this to your executable you wish to run.
      • Program arguments: --arg1 abc --arg2 xyz (Select arguments which reflect your development)
      • Environment Variables: Add to ~/.bashrc or add them here. See definitions above in this document.
      • Ok
      • Bring up program main: ~~/projectx/src/projectXmain.cpp
      • Debug > Start

Anjuta:

Anjuta is a solid, simple, intuitive, bug free IDE for C/C++ development on Linux. Search/Indexing, edit, compile and debug. Anjuta supports Glade Gtk+ GUI builder, profiling (uses gprof) and memory leak detection (uses valgrind) and has an integrated help.

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)

Code Dragon:

Code Dragon is an IDE which specifically supports the wxWindows cross platform GUI libraries which mimic Microsoft's GUI look and feel. The IDE itself was developed using wxWindows widget libraries. Current support and development for this IDE seems to have been dropped although wxWindows development seems to be continuing.

wxWidgets are cross platform and support Win32, Mac OS X, GTK+, X11, Motif, WinCE, and more.

Also see:

Code Warrior:

Code Warrior (by Freescale - was Metrowerks) cross platform, also supports allot of embedded platforms, licensed commercial supported product. The CodeWarrior Development Studio contains all the tools needed to complete a major embedded development project (supports Freescale's IC and microcontroller products).

Also see:

C++ IDE Links:

Other C++ IDEs:

  • OpenAmulet - DARPA funded, developed by the School of Computer Science at Carnegie Mellon University 1994-1997. No longer under development but source is still available.
  • ICS BX Pro - Motif or Qt GUI builder, C/C++ IDE (commercial product)
  • FLTK: Fast Light Toolkit - Cross platform C++ IDE. Supports GUI design and widgets from NEdit and its' own FLUID libraries.
  • Scintilla
  • Source Navigator - Based on Red Hat's original "source navigator" project. [screenshots]
  • Slickedit - commercially developed and supported cross platform IDE for C/C++, Perl, Python and PHP. Has various modes including one which allows Slickedit to resemble Microsoft's Visual C++. Supports recordable macros, code navigation, code refactoring, auto-complete, diffs, etc.
  • VDKBuilder - IDE specifically designed to support GUI construction using the VDK C++ GTK+ wrapper library. Uses SCONS and not Make for builds.
    [Sourceforge project page]
  • WideStudio/MWT - Supports C/C++, Ruby, Perl, Python, Java. Cross platform: Win32, Solaris, MacOS, Linux, FreeBSD. Includes GUI builder/GUI code generator, OpenGL, ODBC, various language encodings.
  • Xwpe-Alpha - Text console based IDE to mimic the old Borland MS-DOS C IDE. [screenshots]
  • Use a combination of single purpose text console or GUI tools to edit (vi/vim/gvim, nedit, emacs/xemacs, gedit), navigate (ctags, cscope) and debug (GDB, ddd).
Also see the YoLinux.com list of Linux text editors.

C/C++ Development environment for Linux:

The following tools will provide the infrastructure for a C++ on Linux development environment:

Note:

Configure a 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__
unix
__unix__

* __i386__
__x86_64__
Red Hat 8 Linux linux
__gnu_linux__
unix
__unix__
* *
Suse 9.2 Linux linux
__gnu_linux__
unix
__unix__



Sun Solaris/SPARC sparc


__arch64
SGI IRIX/MIPS sgi unix
__unix__

_SGI_SOURCE mips
host_mips
Cygwin Win/Intel-32 __CYGWIN32
WIN32
unix
__unix__

* _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

Porting C/C++ code from Solaris to Linux:

Tips:
  • Use macro for GNU C/C++ specific syntax, include files or macros: #ifdef __GNUC__
  • Macros are not always defined in the same header files or perhaps in any at all. Check if defined, if not, include the proper file:
    #ifndef DBL_MAX
        #include <float.h>
    #endif
        
  • Include files for an api are sometimes found in different files.
    • access()
      • Linux: #include <unistd.h>
      • Solaris: #include <sys/fcntl.h>
    • chown()
      • Linux: #include <unistd.h>
      • Solaris: #include <sys/types.h>
    • time()
      • Linux: #include <time.h>
      • Solaris: #include <sys/types.h>
  • Command paths of rm, mv, cp, etc are different for Linux and Solaris:
    #ifdef linux
        sprintf(cmd,"/bin/mv");
    #else
        sprintf(cmd,"/usr/bin/mv");
    #endif
          
  • Hardware differences will have to be accounted for. SPARC is big endian and Intel x86 is little endian. Binary files and messages will be affected.
    See our Big and Little Endian Byte Order conversion tutorial
  • Compiler command line options are different between the GNU and Solaris compilers.
  • Resources:
Solaris libraries:
  • Libraries unique to Solaris can be found in the Open Indiana (was OpenSolaris) GIT repository.
    C Library source code:
    • lltostr() - convert long long to decimal string
    • strlcat() - Appends src to the dstsize buffer at dst
    • Lots of Solaris C lib functions are not supported in GNU C library. See function source: [libc list]
  • CDE - Common Desktop Environment: CDE Sourceforge page [Download source
  • Sun Xview/OpenLook: This was open sourced and can be downloaded and compiled.
    Linux Xview/OpenLook resources

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

  • Include file paths:
    LanguageEnvironment Variable
    CC_INCLUDE_PATH
    C++CPLUS_INCLUDE_PATH
    Objective COBJC_INCLUDE_PATH
    Use colon separated include paths.
    Example: export CPLUS_INCLUDE_PATH=/opt/include:/opt/boost/include

Name mangling and Mixing C and C++:

Name mangling is the C++ compiler technique used to allow function overloading. It allows a function of one name to be used with multiple argument signatures. This is a "behind the scene" compiler operation which does not concern most programmers unless they link with object code generated by other languages including C.

The C++ compiler assumes name mangled function names where the function name includes the argument list data types. For example, the following functions have the following real names in object code symbol table:

C++ function prototypeFunction name in object code (symbol table)
void funcA(int)funcA__Fi
void funcA(int, char)funcA__Fic
void funcA(void)funcA__Fv

To view the function names in the object code, use the tool nm.

To prevent name mangling of C function calls, encapsulate the function declaration with extern"C".

          #ifdef __cplusplus
             extern"C" {
          #endif
          .
          .
          place declarations here
          .
          .
          #ifdef __cplusplus
          }
          #endif

This is required because most programming languages including "C" do not name mangle function names.

For more details on GNU compiler name mangling see Dan Kegel's Name Mangling notes.

For linking with FORTRAN, see the YoLinux.com tutorial mixing C/C++ and FORTRAN.

XML processing in C/C++:

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