8.4.1 Associating Libraries with Modules

You can choose either of two methods for associating your libraries with the modules that use them: you can use the INCLUDELIB directive inside your source files or link the modules from the command line.

Summary: Specify library names with INCLUDELIB.

To associate a specified library with your object code, use INCLUDELIB. You can add this directive to the source file to specify the libraries you want linked, rather than specifying them in the LINK command line. The INCLUDELIB syntax is

INCLUDELIB libraryname

The libraryname can be a file name or a complete path specification. If you do not specify an extension, .LIB is assumed. The libraryname is placed in the comment record of the object file. LINK reads this record and links with the specified library file.

For example, the statement INCLUDELIB GRAPHICS passes a message from the assembler to the linker telling LINK to use library routines from the file GRAPHICS.LIB. If this statement is in the source file DRAW.ASM and GRAPHICS.LIB is in the same directory, the program can be assembled and linked with the following command line:

ML DRAW.ASM

Summary: Link libraries with command-line options.

Without the INCLUDELIB directive, the program DRAW.ASM has to be linked with either of the following command lines:

ML DRAW.ASM GRAPHICS.LIB

ML DRAW /link GRAPHICS

If you want to assemble and link separately, you can use

ML /c DRAW.ASM

LINK DRAW,,,GRAPHICS

Summary: LINK searches in a specific order.

If you do not specify a complete path in the INCLUDELIB statement or at the command line, LINK searches for the library file in the following order:

1.In the current directory

2.In any directories in the library field of the LINK command line

3.In any directories in the LIB environment variable

The LIB utility provided with MASM 6.0 helps you create, organize, and maintain run-time libraries.