DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
C compilation system

Linking with dynamically linked libraries

The cc command line:

cc -dy file1.c file2.c file3.c

creates object files corresponding to each of your source files, and links them with each other to create an executable program. The standard C library that is first searched for in this arrangement (-dy) is a dynamically linked library called libc.so, which means that the functions you have called are linked with your program at run time. (There are some exceptions. Many C library functions have been left out of libc.so by design. If you use one of these functions in your program, the code for the function is incorporated in your executable at link time. The function still automatically linked with your program, only statically rather than dynamically.)


NOTE: The option -dy to cc is necessary to turn on dynamic linking. This option also instructs the compiler to produce object files in ELF format, the only object file format for which dynamic linking is supported.

Now consider the formal basis for this arrangement:

  1. By convention, shared objects, or dynamically linked libraries, are designated by the prefix lib and the suffix .so; archives, or statically linked libraries, are designated by the prefix lib and the suffix .a; static shared libraries are designated by the prefix lib and the suffix _s. The dynamically linked library version of the standard C library is, then, libc.so; libc.a is the archive version; and libc_s.a is the static shared library version.

  2. These conventions are recognized, in turn, by the -l option to the cc command.

    cc -dy file1.c file2.c file3.c -lx -ly_s

    directs the link editor to search the dynamically linked library libx.so, the archive library libx.a, or the static shared library liby_s. The cc command automatically passes -lc to the link editor.

  3. Because of the -dy option, the link editor chooses the dynamically linked library implementation of a library, libx.so, in preference to the archive library implementation, libx.a, in the same directory.

  4. By default, the link editor searches for libraries in the standard places on your system, /usr/ccs/lib and /usr/lib, in that order. The standard libraries supplied by the compilation system normally are kept in /usr/ccs/lib.

Therefore, the cc command line directs the link editor to search /usr/ccs/lib/libc.so rather than its archive library counterpart.

libc.so is one of the dynamically linked libraries supplied by SCO OpenServer Development System. Other dynamically linked libraries are also supplied with the operating system, and usually are kept in the standard places. Of course, you can link your program with libraries that perform other tasks as well. Finally, you can create your own dynamically or statically shared libraries, and archive libraries.


Next topic: Linking with standard libraries
Previous topic: Linking with archive libraries

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003