Real-Time Systems Development

GNU's linker, ld, offers a very wide range of options and facilities, man ld reveals nearly 25 pages of Unix style cryptic flag option summaries to whet your appetite. An important role for the linker is to resolve any external references which remain outstanding, or unsatisfied, from the application code. The linker uses the -L/-l command-line flags to locate library files. For static linking, this means searching through designated library files for the outstanding labels, and extracting the associated function code. If dynamic, shared libraries are to be used, the linker extracts only short stub code which will then be used to make the run-time requests to the operating system to gain access to the DLL module. Effectively this introduces a secondary linking activity, when the operating system has to discover where the called-for shared library modules are stored on disk. This is done through the LD_LIBRARY_PATH environment variable, or paths stored in the /etc/ld.so.conf file. But if this file is changed, the /etc/ld.so.cache file needs to be updated by running the /sbin/ldconfig program. For embedded systems, it may be preferable to force the use of static library code, which can be done using the gcc -static flag.
The ld user can become very confused by the wide range of command- line options, and Gatliff (2001a) helpfully recommends some basic selections. Although generally used only to produce executable programs for desktop PCs, ld can also...