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.
Switches Switch Description -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 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:
Switch | Description |
---|---|
/?, /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:
Switch | Description |
---|---|
- | 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;
Error Messages
- Warning: Public 'symbol name' already in library, redefinition ignored.
- The librarian builds a dictionary of object files corresponding to public symbols in those object files. This is so that an unresolved public symbol can be looked up in the library's dictionary, and the corresponding object file is then linked in. If a particular symbol name appears in more than one object file, there is no longer a unique mapping of symbol names to object files, hence the warning.
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 library 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.