9.4. Linking a Library

Libraries often rely on code in other libraries. Traditionally the way to deal with this is to know what the dependencies are and, when linking an executable, be careful to list all the dependencies on the link line in the correct order. If you have ever built an X Window application using a widget library, you are already familiar with this notion.

Even though you use only the functions in the widget library directly, a typical link command needs to be as follows:

$ gcc -o Xtest -I/usr/X11R6/include Xtest.c -L/usr/X11R6/lib \
-lXm -lXp -lXaw -lXmu -lX11 -lnsl -lsocket

Modern architectures have solved this problem by allowing libraries to be linked into other libraries, but this feature is not yet particularly portable. ...

Get GNU Autoconf, Automake, and Libtool now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.