Building the Library

Building the Library

The database library consists of two files: a public C header file and a C source file. We can build a static library using the commands

gcc -I../include -Wall -c db.c
ar rsv libapue_db.a db.o

Applications that want to link with libapue_db.a will also need to link with libapue.a, since we use some of our common functions in the database library.

If, on the other hand, we want to build a dynamic shared library version of the database library, we can use the following commands:

gcc -I../include -Wall -fPIC -c db.c
gcc -shared -Wl,-soname, -o \
    -L../lib -lapue -lc db.o

The resulting shared library,, needs to be placed in a common directory where the dynamic linker/loader can find it. Alternatively, we can place it in a private directory and modify our LD_LIBRARY_PATH environment variable to include the private directory in the search path of the dynamic linker/loader.

The steps used to build shared libraries vary among platforms. Here, we have shown how to do it on a Linux system with the GNU C compiler.

     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows