Installing Libraries: A Lab Exercise

Installing Libraries A Lab Exercise

A number of examples in this book make use of classes found in one of the libraries that were written for this book. The source code for these classes is available for download.[4] In the HTML version of this book, the class names are all hyperlinked to API docs.[5] Here you learn how to download and install these extra classes.



Instructions for installing libraries on a *nix platform for use with the book examples follow.

  • Create a ~/projects/libs directory.
  • Create a shell/environment variable CPPLIBS that contains the absolute path of projects/libs.
  • You should already have a shell/environment variable QTDIR that contains the absolute path of the directory that contains Qt 4.[6]

    [6] This is not required by Qt 4, but is required by Qt 3 and KDE, and is used for Qt 4 as a way of pointing to "the current version of Qt that you are using."

  • Download, utils.tar.gz, and dataobjects.tar.gz.[7]

    [7] From

  • Unpack these two tarballs in the $CPPLIBS directory. That should result in two new subdirectories, $CPPLIBS/utils and $CPPLIBS/dataobjects.
  • Create or modify a $CPPLIBS/ SUBDIRS project to build only libutils followed by libdataobjects.
  • Build the libraries from the libs directory in two steps:

    1. qmake // to create a Makefile
    2. make // to build the library
  • Verify that the libraries are built and that the shared object files (e.g., are located in the $CPPLIBS directory.

7.4.1. Fixing the Linker Path

  • Update the shell/environment variable LD_LIBRARY_PATH (*nix) or PATH (win32) to include CPPLIBS.
  • Create a projects/tests directory. This is where you can keep code for testing various library components.
  • Download main.cpp from Example 6.26 into projects/tests and write/modify a file to build that application using the utils library.
  • Run the application.
  • Verify that it gives the same output that we displayed back in Chapter 6 when we discussed the ArgumentList class.

On a *nix platform a shell script is generally used to define environment variables. Example 7.2 shows a bash script that handles the job.

Example 7.2. src/bash/

export CPPLIBS=$HOME/cs331/projects/libs
export QTDIR=/usr/local/qt
export PATH=$QTDIR/bin:$PATH

You can run this script by typing one of the following commands:




Notice the dot (.) at the beginning of the second version. In the bash shell, the dot is equivalent to the command, source.

If you want to make sure that these environment variables are automatically set at the start of each shell, you can source the script from ~/.bashrc, which runs automatically whenever bash starts.

Hamish Whittal has put together a very nice online guide to shell scripting at

Part I: Introduction to C++ and Qt 4

C++ Introduction


Introduction to Qt



Inheritance and Polymorphism

Part II: Higher-Level Programming


Introduction to Design Patterns


Generics and Containers

Qt GUI Widgets


Validation and Regular Expressions

Parsing XML

Meta Objects, Properties, and Reflective Programming

More Design Patterns

Models and Views

Qt SQL Classes

Part III: C++ Language Reference

Types and Expressions

Scope and Storage Class

Statements and Control Structures

Memory Access

Chapter Summary

Inheritance in Detail

Miscellaneous Topics

Part IV: Programming Assignments

MP3 Jukebox Assignments

Part V: Appendices

MP3 Jukebox Assignments


MP3 Jukebox Assignments

An Introduction to Design Patterns in C++ with Qt 4
An Introduction to Design Patterns in C++ with Qt 4
ISBN: 0131879057
EAN: 2147483647
Year: 2004
Pages: 268 © 2008-2020.
If you may any questions please contact us: