[Home]
[Search]
[CTG]
[RTL]
[IDDE]
Last update Oct 12, 2002
LIB: Object File Librarian
A library manager is a utility that maintains object library files. Object
libraries are collections of related object (.obj) files,
such as a set of
graphics functions, or the run-time libraries supplied with this
compiler. Object libraries are useful for linking them as a
single, convenient file, rather than as many separate files. Creating
an object library does not change the contents of the object files or
how they work. A library just gathers object files in one place.
Use LIB to create, maintain, and customize object library files. LIB
enables putting objects into libraries, replacing objects with newer
versions, deleting objects from libraries, and extracting
objects from libraries.
LIB can generate a text listing of the contents of a library.
LIB handles both 16-and 32-bit object files in Intel OMF format.
LIB command syntax
lib switches... libfile objfiles...
- switches...
- Zero or more of the following.
If none of -c, -d or -x is specified, the default action is to
add the objfiles to the library.
- -c
- Create new library and insert objfiles into it.
- -d
- Delete objfiles from library.
- -h
- Print brief help.
- -i
- Ignore case of public symbols. The default is to be
case sensitive.
- -n
- Do not make a backup file of the original library.
- -l
- Create text listing file of the symbols in the library.
The listing file will be the name of the library with the .lst
extension.
- -pnnn
- Set page size to nnn (a power of 2).
- -x
- Extract objfiles from library.
- libfile
- The name of the library file. The default extension is .lib.
- objfiles...
- List of object files to be added, deleted, or extracted.
The default extension is .obj.
Library files can also be specified here, in order to insert
whole libraries.
Backup Libraries
If a library file is modified or rewritten, an existing library
file of the same name is renamed to a file with a .bak
extension. (This action is disabled with the -n switch.)
Any previous file of the same name with the .bak extension
is deleted.
Examples
lib -h
Print help message.
lib foo a b c.obj
Create a library foo.lib and insert the object files
a.obj b.obj and c.obj.
lib -l foo
Create listing file foo.lst of contents of foo.lib.
lib -d foo.lib a
Delete the object a.obj from foo.lib.
lib -x foo.lib b
Extract the object b.obj from foo.lib and
write it to file b.obj.
lib foo.lib bar.lib a.obj
Add the contents of bar.lib and
a.obj to foo.lib.
Using LIB with SMAKE
The usual technique is:
OBJS=a.obj b.obj c.obj
foo.lib : $(OBJS)
lib -c foo.lib $(OBJS)
If the list of OBJS gets too long for the command line, SMAKE can
automatically create a response file. Use an SMAKE command like:
OBJS=a.obj b.obj c.obj
foo.lib : $(OBJS)
lib -c foo.lib \
@<<
$(OBJS)
<<
Using LIB with MAKE
The usual technique is:
OBJS=a.obj b.obj c.obj
foo.lib : $(OBJS)
lib -c foo.lib $(OBJS)
If the list of OBJS gets too long for the command line,
MAKE will automatically create a response file that LIB will
use.
Obsolete LIB command syntax
For compatibility with older makefiles and batch files, LIB supports
an older command line syntax. Such makefiles should be upgraded to the
new command syntax.
Arguments are passed to LIB via:
- the command line
- a response file (similar to the linker response file)
- interactively from the command prompt
LIB commands have the following format:
lib lib-file [switches][action-files],[list-file][;]
lib-file is the name of the library file to create or change.
Its default file extension is .lib.
The switches are:
- /?, /H
- Print help information.
- /B
- Run LIB in batch mode.
- /C
- Create a new library lib-file if one
does not exist. Use to create a new library without
being prompted to do so.
- /I
- Ignore case in public symbols (default).
- /N
- Do not back up the original library.
The default behavior is to save a backup of the original library file
with the extension .bak.
- /NOE
- LIB ignores this switch.
- /NOI
- Treat uppercase and lowercase letters as distinct, and
mark the library as case-sensitive. This applies only to
public symbols. The default is /I.
- /NOL
- Do not display copyright message.
- /P:num
- Set page size to num (a power of 2).
The action-files specify the objects on which to act and
what to do with them. The action-files must be one or
more object files in the current directory. The default extension
for object files is .obj. When LIB puts an
object file into a library, it gives the object's module the name of the
object file in uppercase and without an extension.
To specify what to do with each object file, put one of
the following switches before the name(s) of the action-files:
- -
- Removes the object from the library.
- +
- Adds the object to the library.
If the library already contains an object of the same name,
LIB prints an error message and doesn't add the object.
- *
- Copies the object into a separate object file,
leaving the object in the library.
- +-, -+
- Replaces an existing object in the library
with a new version.
- *-, -*
- Extracts the object module into an object
file and deletes it from the library.
The list-file produces a file listing the contents of the library.
The file
first lists all the public symbols in alphabetical order with the name
of the modules to which they belong. Next, it lists the modules
alphabetically with the public symbols in them.
The default list-file extension is .lst.
If there is a list-file
but no action-files, LIB produces a list file without modifying the
library.
Concatenating libraries
To concatenate two libraries, specify one as the lib-file and the other
as an action-file. LIB adds the modules from the action-file
library to the other library without changing the names of the modules.
Note:
LIB doesn't allow two modules to contain the same
public symbol.
Using LIB interactively
If LIB is run with no arguments, it prompts for the required
arguments. Use the ampersand (&) character to continue input on a
new line.
Response files
You can use LIB with a response file, which contains the responses
that the compiler would ask for if used interactively. For
example, the response file below adds several objects to the library
mywindow.lib and produces a listing file:
\dm\lib\mywindow.lib /c
+winopen+winblank+winmove+winhide&
+winshow+winputs+wingets+winprint
\dm\mywin.lst;
If the response file is makewin.rsp, use LIB like this:
lib @makewin.rsp
Don't use filenames beginning with @ because LIB mistakes
it for a response file.
Using LIB with SMAKE
The usual technique is:
OBJS=a.obj b.obj c.obj
foo.lib : $(OBJS)
-del foo.lib
lib foo.lib/C/NOI +a+b+c;
If the list of OBJS gets too long for the command line, SMAKE can
automatically create a response file. Use an SMAKE command like:
OBJS=a.obj b.obj c.obj
foo.lib : $(OBJS)
-del foo.lib
lib foo.lib/C/NOI \
@<<
+a&
+b&
+c;
<<
Using LIB with MAKE
The usual technique is:
OBJS=a.obj b.obj c.obj
foo.lib : $(OBJS)
-del foo.lib
lib foo.lib/C/NOI +a+b+c;
If the list of OBJS gets too long for the command line,
use multiple LIB commands:
OBJS=a.obj b.obj c.obj
foo.lib : $(OBJS)
-del foo.lib
lib foo.lib/C/NOI +a+b;
lib foo.lib/NOI +c;
Bugs
- LIB doesn't work with COFF files. To work around, use
COFF2OMF
to convert them to Intel OMF format.
- Due to the Microsoft OMF lib file format, there is a
hard limit on the length of an identifier of slightly less
than 512 characters. The only way around this is to use
a shorter name, or to link in those modules separately that
use longer names.
Copyright © 1995-2002 Digital Mars. All Rights Reserved.