User manual

ST Assembler-Linker Librarian
Doc ID 11392 Rev 4 51/89
8 Librarian
8.1 Overview
If you do a lot of work on similar boards especially those with the same processor, it makes
a great deal of sense to reuse lumps of code you have already written to do the same task in
a different program. At the simplest level, you could just copy the source code as a block of
text into the new program. This works fine, but has a subtle disadvantage: if you update the
subroutine, you have to hunt around all the usages of it, performing the update on each.
To get around this problem, many people have the source for common routines in one place,
and link the .OBJ module with each program needing routine. Then you only need to update
the source code once, reassemble it to get a new .OBJ file, then link again all the users of
the routine, who will now have the new .OBJ file.
While this scheme works well, it generates some problems of its own. For example, each
routine needs its own .OBJ file. By nature, these common routines tend to be small, so you
end up giving dozens of extra .OBJ modules to the linker, and having the .OBJ modules
scattered around your hard disk.
The base concept of a librarian is to combine all these small, useful .OBJ modules into one
large .LIB library file. You could then tell the linker about the library, and it takes care of
which .OBJ modules to pull in to link. It would know which ones to pull in by the fact that the
main code being linked would have undefined externals, for example, to call the missing
library routines. The librarian simply takes each undefined external in turn, and checks it
against all the modules in the library. If any of the modules declares a PUBLIC of the same
name, it knows you need that .OBJ module and it includes it automatically.
8.2 Invoking the librarian
The librarian is called LIB, and takes one command line argument that is the name of the
library to operate on. If not given, you are prompted for it.
LIB [library name]
.LIB is added if the suffix is left off.
If the library you indicate does not exist, LIB asks you if it is a new library. For example:
LIB LIB1
STMicroelectronics - Librarian - rel 1.00
Couldn't open Library file 'LIB1.LIB'
is it a new file? (y/n): y
If the answer is 'n', LIB aborts. If the library exists, LIB prints up a report on the library.
Library LIB1.LIB is 2K long.
16/1024 Public labels used in 2/128 modules.
Next comes the main prompt:
LIB1.LIB: Operation (<ENTER> for help):
Pressing ENTER gives you access to the options shown in Table 17.