A “library” is a collection of commonly used routines and data. The definitions of these routines and data are grouped into one or more modules within the library. The linker handles references to externally defined routines and data by looking in libraries and linking the definitions to your program.
You can use two kinds of libraries when linking: default libraries provided by QuickC for Windows and libraries created by you or a third party. Default libraries are installed during setup; for more information about default libraries, see the Development Environment Guide. You can create your own libraries by using the LIB utility; these libraries, as well as third-party libraries, are referred to in this section as user-created libraries. The following sections discuss how user-created and default libraries are specified, located, and used.
You provide user-created libraries to the linker by listing them in the project.
·To list libraries in the project:
1.From the Project menu, choose Edit. The Edit Project dialog box appears. (See Figure 9.1.)
2.Add the names of your library files to the Project list.
Libraries must have the filename extension .LIB.
You do not need to list default libraries in the project. Each .OBJ file in your project contains the name of a default library. The linker reads this name, finds the library, and uses it to resolve references to C run-time routines called in the .OBJ file.
You might need to list a library in the project when you want to use a default library that has been renamed or to specify a library other than the default named in the object file. (For example, you would list a library that handles floating-point arithmetic differently from the default library.)
·To prevent the linker from using the default libraries:
1.From the Options menu, choose Project. The Project dialog box appears. (See Figure 9.2.)
2.From the Customize Build Options box, choose the Linker button. The Customize Linker Options dialog box appears. (See Figure 9.3.)
3.In the Global Options box, turn on the Ignore Default Library check box.
Ignoring default libraries causes unresolved references in the object files, so you must specify alternative libraries in the project to resolve these references.
Libraries listed in the project must exist in the directory specified with the library filename. Default libraries must exist either in the current directory or in a directory specified with the LIB environment variable.
You can provide a default library in another location by either of two methods.
·To specify a single library:
1.From the Project menu, choose Edit. The Edit Project dialog box appears. (See Figure 9.1.)
2.Add the name of the desired library file to the Project list.
Listed files always have an explicitly specified absolute path.
·To add a directory to the search path for all default libraries:
1.From the Options menu, choose Directories. The Directories dialog box appears (Figure 9.4).
2.Edit the Library Files Path text box to specify the directory or directories containing your default libraries. Separate multiple directories with a semicolon (;).
This does not change the value of LIB stored by DOS. The linker checks directories specified in this text box before it checks the directories in LIB.
The linker first looks for a definition of the libraries you specify in the Project list, in the order in which you specify them. It then looks in the default libraries. If you explicitly list a default library in the project, the linker looks in that library in the order that it is listed in the Project list. When the linker finds a needed definition, it brings in all the definitions that exist in that module of the library, whether they are needed or not. If the linker cannot find a needed definition, it issues an error message:
unresolved external
Summary: Multiple definitions for the same reference can cause errors.
If a reference is defined in more than one library, the linker uses the first definition it finds as it searches the libraries in order. A duplicate definition may not be a problem if the later definition is in a library module that the linker never uses. However, if the duplicate definition is in a module that contains another needed definition, the entire module, including the duplicate definition, is linked into the program, causing the linker to issue an error message:
symbol defined more than once
Multiple definitions can also cause a problem if the Extended Dictionary check box is turned on. (See “Global Options” on page 214.) An “extended dictionary” in a library is a summary of the references defined for all modules in that library. The linker can use this summary to speed the process of searching libraries. If the linker finds a previously resolved reference listed in an extended dictionary, even if the definition is in a module that will not be linked to the program, it assumes that a duplicate definition exists and it issues an error message:
symbol multiply defined, use /NOE
If this error occurs, turn off the Extended Dictionary check box and build your program again.