20.7. 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 commandsgcc -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,libapue_db.so.1 -o libapue_db.so.1 -L../lib -lapue -lc db.o The resulting shared library, libapue_db.so.1, 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. |