[ fromfile: installing-libs.xml id: installing-libs ]
Abstract
A number of examples in this book make use of classes found in libraries that were written for this book. The source code for these classes is available for download. API documentation is included, generated with Doxygen. In this exercise, you can see how to build and install some libraries.
As we suggested in Section 7.1 and Section 7.1.2:
Create a directory especially for your C++/Qt work; e.g., ~/oop/projects/
.
Download src.tar.gz
from the distfiles directory.
Unpack this tarball in the new directory. That should result in a src/libs
directory with a number of subdirectories including libs/dataobjects
and libs/customer
.
Examine the subdirs
project file, named libs.pro
, in the src/libs
directory.
It is designed to build the libraries and the tests.
Feel free to comment out the libraries and tests you do not plan to use, but do not change the order of the libraries.
Create a shell/environment variable named CPPLIBS
that contains the absolute path of your new libs
directory. For convenience, you can place the definition for this environment variable inside a shell script, as demonstrated in Example 7.2.
Note | |
---|---|
If you decide to comment out a particular library directory in Reminder: You can comment out any line in a project file by inserting the poundsign char '#' at the beginning of that line. |
TEMPLATE = subdirs CPPLIBS=$$(CPPLIBS) isEmpty(CPPLIBS) { error("Define CPPLIBS environment variable to point to this location.") } SUBDIRS += dataobjects \ actioneditor \ customer \ metadata \ sqlmetadata
Build the libraries from the libs directory in two steps:
qmake -recursive
// creates Makefiles
in current dir and in each subdir.
make
// builds the libraries and tests.[32]
Verify that the libraries are built and that the shared object files (e.g., libdataobjects.so [33]) are located in the CPPLIBS directory.
Following is an abbreviated directory listing from a typical linux box:
libs> ls -l drwxr-xr-x 5 dataobjects lrwxrwxrwx 1 libactioneditor.so -> libactioneditor.so.1.0.0 lrwxrwxrwx 1 libactioneditor.so.1 -> libactioneditor.so.1.0.0 lrwxrwxrwx 1 libactioneditor.so.1.0 -> libactioneditor.so.1.0.0 -rwxrwxr-x 1 libactioneditor.so.1.0.0 [...] lrwxrwxrwx 1 libdataobjects.so -> libdataobjects.so.1.0.0 lrwxrwxrwx 1 libdataobjects.so.1 -> libdataobjects.so.1.0.0 lrwxrwxrwx 1 libdataobjects.so.1.0 -> libdataobjects.so.1.0.0 -rwxr-xr-x 1 libdataobjects.so.1.0.0 -rw-r--r-- 1 libs.pro -rw-r--r-- 1 Makefile libs>
Lines that begin with drwxr-xr-x
are directories. Lines that begin with lrwxrwxrwx
are symbolic links. Use Google to find out why each shared object file has three symbolic links.
Update the shell/environment variable LD_LIBRARY_PATH
(*nix) or PATH
(win32) to include CPPLIBS
using the appropriate syntax.
Create a projects/tests
directory. This is where you can keep code for testing various library components.
Run the test apps that came with the libs
tarball. They are in subdirs of libs/tests that correspond to the libraries that you built.
Note | |
---|---|
On a *nix platform a shell script is generally used to define environment variables. Example 7.2 shows a bash shell script that handles the job. Example 7.2. src/bash/env-script.sh export CPPLIBS=$HOME/oop/projects/libs export LD_LIBRARY_PATH=$CPPLIBS Note the bash syntax details in this script:
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, 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 nice online course on Shell Scripting. |
[32] You may need to install some specialized Qt packages before building some of our libraries. For example, the libphonon-dev package is required for our phononmetadata library. The linker will inform you of these dependencies.
[33] Or on Windows, libdataobjects.lib
and dataobjects.dll
, the latter which must be in a directory listed in your PATH
, so be sure to include %CPPLIBS%
in your PATH.
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |