Previous Next

Specifying Libraries

Unlike some other environments that use the LIB environment variable, the Build utility always requires the full path. The purpose of this is to eliminate any ambiguities in the build process.

For instance, some build processes rely on the linker to "figure out" the correct libraries by using paths stored in the LIB environment variable in combination with a list of default libraries stored in the objects. However, this approach has the inherent (and undesirable) side effect of making it difficult to either know, or control, which libraries are used in your build process.

On the other hand, the Build utility requires that you specify the full path to each library you use. It will disable any default library lookup that the linker might attempt to use. Additionally, when specifying the libraries, you should try to abstract any absolute dependencies that might exist in the path. The build process provides an asterisk (*) to take the place of the platform. You can use the BASEDIR macro to take the place of the root of the source tree. You can use DDK_LIB_PATH to refer to libraries that ship as part of the Windows DDK.

Additionally, you should use an asterisk to indicate the target platform in the path. For example, assume you are building a typical Win32® Windows .exe file. Generally, this would require you to link against kernel32.lib, user32.lib, gdi32.lib, and maybe your own component library, mylib.lib. The following is what the TARGETLIBS macro would look like:

TARGETLIBS = \
# Note: SDK_LIB_PATH already ends in “\*” so you should no include it when using
# the macro.
$(SDK_LIB_PATH)\kernel32.lib \
$(SDK_LIB_PATH)\user32.lib \
$(SDK_LIB_PATH)\gdi32.lib \
..\mylib\obj\*\mylib.lib

When building on x86, this would mean the same as:

TARGETLIBS = \
$(BASEDIR)\lib\i386\kernel32.lib \
$(BASEDIR)\lib\i386\user32.lib \
$(BASEDIR)\lib\i386\gdi32.lib \
..\mylib\obj\i386\mylib.lib

To build a particular set of build products, change to a directory that contains either a dirs file or a sources file. Run the Build utility. The utility will automatically build the products specified in the sources file of each subdirectory.

For example, if a sources file describes a library called "mylib", using the following command line will build the library:

build -386