1.3.1. The Unix™ world

If a remark is allowed to the author: This is not the best of all worlds, but, after all, a beautiful world!

Compiling

In order to compile it is necessary to inform the compiler about the path to the LEDA header files.

In the standard installation under Unix the header files are located in the directory incl below the LEDA root directory, which we will mark by LEDAROOT in the following. We should therefore let an environment variable LEDAROOT point at this root directory. For example, on the author's machine this is the directory /usr/local/LEDA/LEDA4.4. Therefore we set the variable LEDAROOT in the shell as follows:

$ LEDAROOT = /usr/local/LEDA/LEDA4.4
$ export LEDAROOT

We inform the compiler by means of the option -I where it can find the header files:

$ g++ -c HelloLEDAWorld.C -I$LEDAROOT/incl

By this the corresponding object file should have been created:

$ ls HelloLEDAWorld.*
HelloLEDAWorld.C    HelloLEDAWorld.o

Linking

Now we must link the file HelloLEDAWorld.o, which has been just created, with the LEDA libraries to obtain a runnable program.

In LEDA versions prior to 6.0, there are 7 different libraries, as listed in Table 1.1; the static libraries end by .a, the dynamic ones by .so:

Table 1.1. The LEDA libraries

LibraryContent
libL.a (libL.so)Base library with the basic data types (simple data types, container types, and priority queues)
libG.a (libG.so)Library with code for graphs
libG2.a (libG2.so)Library with code for semi-dynamic graphs
libP.a (libP.so)Library with code for plane geometry
lib3D.a (lib3D.so)Library with code for 3-dimensional geometry
libW.a (libW.so)Library with code for windows and graphical user interfaces
libGeoWin.a (libGeoWin.so)Library with code for a graphical editor for geometric objects

As of version 6.0 of LEDA, there is only one library on Unix™ systems: libleda.

Which of these libraries are actually available on our system (before version 6.0) and what the libleda contains (as of version 6.0) depends on which LEDA package is installed. In version prior to 6.0, however, the base library libL is available in every case (the static or dynamic version or both versions simultaneously). In the first four chapters of this tutorial solely this library libL or the library libleda of the Free Edition is needed.

Now, to link the object file HelloLEDAWorld.o with the base library (this one contains the code for the class string), we must inform the compiler where it can find this library. This can be managed for example by means of the option -L. On the author's machine the libraries are located in the directory /usr/local/LEDA/LEDA4.4, that is, the LEDA root directory. Linking therefore is carried out by the following call of the compiler from the shell:

$ g++ -o HelloLEDAWorld HelloLEDAWorld.o -L$LEDAROOT -lL -lm

[Important]Important

The mathematical library libm must always be linked to LEDA programs, and always as the last library in the series.

In LEDA versions prior to 6.0, if more than only the base library libL shall be linked, then the following order must be adhered to: -lD3 -lP -lG -lL -lm. Furthermore, the manual describes in detail what has to be done to use the graphic libraries libW and libGeoWin.

As of version 6.0 of LEDA, the libX11 library must always be linked to LEDA programs. The following order must be adhered to: -lleda -lX11 -lm

If both the dynamic and the static libraries are located in the same directory, then linking is always performed against the dynamic ones. To force a static linking, the static libraries must be put in a directory of their own and the path there must be specified correspondingly.

With such a simple program, compiling and linking can be done in one single step, of course:

$ g++ -o HelloLEDAWorld HelloLEDAWorld.C -I$LEDAROOT/incl -L$LEDAROOT -lL -lm

Of course we will not stop at Hello world!, but soon write larger programs with more than one compilation unit. The use of a makefile comes in handy here. A generic makefile, which may serve as a starting point for other makefiles, is shown in the following:

Filename: Makefile.generic
LEDA users as of version 5.0: Note that header files are now partitioned into modules (subfolders)!
# Set the following Makefile variables according to your needs

LEDAINCLDIR = /usr/local/LEDA/LEDA4.4/incl
LEDALIBDIR  = /usr/local/LEDA/LEDA4.4
LEDALIBS    = -lL -lm
#LEDALIBS   = -lG -lL -lm
#LEDALIBS   = -lP -lG -lL -lm
#LEDALIBS   = -lD3 -lP -lG -lL -lm

CC = g++
CXXFLAGS = -Wall

# End of customizing region

# Implicit rule: How to make an executable from a .C-file
%: %.C
        # The following lines must start with a tab, not with blanks!
        # So beware when you copy and paste!
        ${CC} -o $@ $< ${CXXFLAGS} \
              -I${LEDAINCLDIR} -L${LEDALIBDIR} ${LEDALIBS}

Then a call

$ make -f Makefile.generic HelloLEDAWorld

creates our HelloLEDAWorld in an automagical way.

Starting

We are now finally ready to let HelloLEDAWorld run! Some small steps for a program, a large step for a prospective LEDA programmer! But wait a moment, not so fast. If we have linked dynamically, we still must inform the loader where it can find the dynamic libraries by adapting the environment variable LD_LIBRARY_PATH:

$ export LD_LIBRARY_PATH = $LD_LIBRARY_PATH:/usr/local/LEDA/LEDA4.4

Now nothing gets in the way of an algorithmically faultless production of the most famous greeting message in the programming world:

$ HelloLEDAWorld
Hello LEDA world!

And as already mentioned, the rest is no longer hard from now on...




Imprint-Dataprotection