[ fromfile: installing-libs.xml id: installing-libs ]
Abstract
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. In the HTML version of this book, the class names are all hyperlinked to API docs. In this exercise, we will build and install some libraries.
Instructions for installing libraries on a *nix platform for use with the book examples follow. For help installing Qt and MySQL on Windows with MinGW, check the QtCentre.
Create a ~/cs331/projects/libs directory.
Create a shell/environment variable CPPLIBS that contains the absolute path of projects/libs.
Download utils.tar.gz and dataobjects.tar.gz from the distfiles directory.
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/libs.pro SUBDIRS project to build only libutils followed by libdataobjects.
Build the libraries from the libs directory in two steps:
qmake // to create a Makefile
make // to build the library
Verify that the libraries are built and that the shared object files (e.g., libutils.so [25]) are located in the $CPPLIBS directory.
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 tests.pro 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.
| Note | |
|---|---|
On a *nix platform a shell script is generally used to define environment variables. Example 7.3 shows a bash script that handles the job. Example 7.3. src/bash/env-script.sh export CPPLIBS=$HOME/cs331/projects/libs export QT4=/usr/local/qt export LD_LIBRARY_PATH=$QT4/lib:$CPPLIBS export PATH=$QT4/bin:$PATH You can run this script by typing one of the following commands:
source env-script.sh
or
. env-script.sh
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 Hamish Whittal has put together a very nice online guide to Shell Scripting. |
[25] Or on Windows, libutils.lib and utils.dll, the latter which must be in a directory listed in your PATH, so be sure to include %CPPLIBS% in your PATH.
| Generated: $Date: 2009-09-08 12:15:32 -0400 (Tue, 08 Sep 2009) $ | © 2009 Alan Ezust and Paul Ezust. |