www.digitalmars.com [Home] [Search] [Contents]

LIB: Object File Librarian

A library manager is a utility that maintains object library files. Object libraries are collections of related object files, such as a set of graphics functions, or the run-time libraries supplied with this compiler. Object libraries are useful because you can link 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 lets you put new objects into libraries, replace objects with newer versions, remove objects from libraries, and make copies of them as separate object (.obj) files. LIB can also generate a readable listing of the contents of a library.

LIB handles both 16-and 32-bit object files in Intel OMF format.

LIB command syntax

LIB can be invoked on the command line, in a batch file, or from SMAKE or MAKE. Pass arguments to LIB in one of two ways: on the LIB command line or via a response file (similar to a linker response file).

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 you want to act and what you want 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.

Using 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.

Bugs

LIB doesn't work with COFF files. To work around, use COFF2OMF to convert them to Intel OMF format.