|ARM Technical Support Knowledge Articles|
A library is simply a collection of objects and can be added to a link line in the same way an object can be. However the linker treats objects within a library differently to objects specified on the command line.
The following is a functional description of what happens during the linking process (obviously there are various opportunities for optimisation);
Depending on the application you are building there might be no symbol references left in the list in which case the link is finished and no libraries are required.
Typically however there are some references left in the list and at this stage (and only at this stage) the linker begins searching the libraries to find suitable matching definitions.
Once all the references have been resolved the linking process has finished and the linker stops reading library symbol tables and loading library objects.
If all the libraries have been scanned and there are still symbol references left then these are considered to be unresolved and an error is raised.
This process is documented in the Creating and Using libraries section of the Linker and Utilities guide supplied with the tools and can be better understood by looking at the output of the --verbose switch (-verbose in ADS) i.e.
armlink --verbose -o image.axf a.o b.o c.o lib.a
The --verbose switch is extremely useful in diagnosing link problems.
This process has various intended consequences; the most common are listed below.
If you have a library and wish to force an object within it to be loaded by the linker then you should refer to that object and library explicitly on the linker command line like this;
armlink -o image.axf a.o b.o c.o lib.a(important_object.o)
A library is typically useful where there are optional pieces of code in your system (perhaps dependent on hardware configuration and you wish to allow the linker to make the selection). They are also useful for providing code to customers who will be changing such a configuration. They are not especially useful for packaging up a large number of objects all of which will be required in the final link step. In this case objects should be partially linked instead to create a single, large, combined object. Partial linking is accomplished with
armlink --partial -o combined_object.o a.o b.o c.o
System libraries will not be included in the combined object. Partial linking has several advantages including reducing debug information and a faster final link step.
Article last edited on: 2009-04-16 16:00:52
Did you find this article helpful? Yes No
How can we improve this article?