12.3.4 The libraries Field

You can specify one or more standard or import libraries (not DLLs) in the libraries field. If you name more than one library, separate the names with a plus sign (+) or a space. To extend libraries to the following line, type a plus sign (+) as the last character on the current line, press ENTER, and continue. Do not split a name across lines. If you specify the base name of a library without an extension, LINK assumes a default .LIB extension.

If no library is specified, LINK searches only the default libraries named in the object files to resolve unresolved references. If one or more libraries are specified, LINK searches them in the order named before searching the default libraries.

You can tell LINK to search additional directories for specified or default libraries by giving a drive name or path specification in the libraries field; end the specification with a backslash (\). (If you don't include the backslash, LINK assumes the last element of the path is a library file.) LINK looks for files ending in .LIB in these directories.

You can specify a total of 32 paths or libraries in the field. If you give more than 32 paths or libraries, LINK ignores the additional specifications without warning you.

You might need to specify library names when you want to

Use a default library that has been renamed.

Specify a library other than the default named in the object file (for example, a library that handles floating-point arithmetic differently from the default library).

Search additional libraries.

Find a library not in the current directory and not in a directory specified by the LIB environment variable.

12.3.4.1 Overriding Default-Library Searches

Most compilers insert the names of the required language libraries in the object files. LINK searches for these default libraries automatically; you do not need to specify them in the libraries field. The libraries must already exist with the name expected by LINK. Default-library names usually refer to combined libraries built and named during setup; consult your compiler documentation for more information about default libraries.

To make LINK ignore the default libraries, use the /NOD option. This leaves unresolved references in the object files, so you must use the libraries field to specify the alternative libraries that LINK is to search.

12.3.4.2 Import Libraries

You can specify import libraries created by the IMPLIB utility anywhere you can specify standard libraries. You can also use the LIB utility to combine import libraries and standard libraries. These combined libraries can then be specified in the libraries field.

12.3.4.3 How LINK Resolves References

LINK searches static libraries to resolve external references. A static library is either a standard library created by the LIB utility or an import library created by the IMPLIB utility. The linker searches first in the libraries and library directories you specify (in the order you specify them), then in the default libraries. If a default library is explicitly specified, it is searched in the order it is given.

LINK uses only those library modules needed to resolve external references, not the entire library. However, if you enter a library as a load library in the objfiles field, all the modules of a load library are added to the main output.

12.3.4.4 How LINK Searches for Library Files

When searching for libraries, LINK looks in the following locations in this order:

1.The directory specified for the file (if a path is included). If the file is not in that directory, the search terminates. (The default libraries named in object files by Microsoft compilers do not include path specifications.)

2.The current directory.

3.Any directories in the libraries field.

4.Any directories specified in the LIB environment variable.

If LINK cannot locate a library file, it prompts you to enter the location. The /BATCH option disables this prompting.

Example

The following is a specification in the libraries field:

C:\TESTLIB\ NEWLIBV3 C:\MYLIBS\SPECIAL

LINK searches NEWLIBV3.LIB first for unresolved references. Since no directory is specified for NEWLIBV3.LIB, LINK searches the following locations in this order:

1.The current directory

2.The C:\TESTLIB\ directory

3.The directories in the LIB environment variable

If LINK still cannot find NEWLIBV3.LIB, it prompts you with the message

Enter new file spec

You can then enter either a path to the library or a full pathname for another library.

If unresolved references remain after searching NEWLIBV3.LIB, LINK then searches the library C:\MYLIBS\SPECIAL.LIB. If LINK cannot find this library, it prompts you as described above for NEWLIBV3.LIB. If there are still unresolved references, LINK searches the default libraries.