• Keine Ergebnisse gefunden

Using the linker: TLINK

Im Dokument or an (Seite 156-160)

TLINK and TLINK32 are command-line tools that combine object modules (.OBJ files) and library modules (.LIB files) to produce executable files. The IDE uses built-in versions of the linkers. Because the compiler

automatically calls the linker, you don't need to use TLINK unless you suppress the linking stage of compiling (see the -c compiler option). Unless otherwise specified, instructions and options for TLINK also apply to TLINK32.

TLINK uses a configuration file called TLINK.CFG, a response file

(optional), and command-line options to link object modules, libraries, and resources into an executable file (.EXE or .DLL). The IDE linker uses the options specified in the Project Options dialog box in the Linker section.

The syntax for TLINK is

TLINK [@respfile] [options] startupfile myobjs, exename, [mapfile], [mylibs] runtimelib [import], [deffile], [resfiles]

where

• options are TLINK options that control how TLINK works. For example, options specify whether to produce an .EXE or a DLL file. TLINK options must be preceded by either a slash (/) or a hyphen (-). To turn off a default option,-place a hyphen after the option (for example, -P-).

Table 9.3 lists the TLINK options .

• startupfile is a Borland initialization module for executables or DLLs that arranges the order of the various segments of the program. The initialization module must appear first in the object file list. If it isn't first, the program segments might not be placed in memory properly, which could cause some frustrating program bugs. Failure to link the correct initialization module usually results in a long list of error messages telling you that certain identifiers are unresolved, or that no stack has been created.

TLlNK.CFG The IDE uses linker

options specified in project options and style sheets. See Chapter 2 for more information on setting options for project.

144

_ myobj s are the .OB] files you want linked. Specify the path if the files aren't in the current directory.

_ exename is the name you want given to the executable file (.EXE or .DLL).

If you don't specify an executable file name, TLINK derives the name of the executable by appending .EXE or .DLL to the first object file name listed. Be sure you give an explicit name for the executable file name on the TLINK command line. Otherwise, your program name will be something like .C02.EXE-which probably isn't what you wanted.

_ mapfile (optional) is the name you want given to the map file. If you don't specify a name, the map file name is given the same asexefile (but with the .MAP extension).

_ mylibs (optional) are the library files you want included at link time. If these files aren't in the current directory or the search path (see the IL option) then you must include their paths.

_ runtimelib is the Borland run-time library. If no libraries are included, none are linked.

_ importlib is the Windows import library, which provides access to the Microsoft Windows API functions.

_ deffile is the module-definition file (.DEF) for a Windows executable. If you don't specify a .DEF file, TLINK creates an application based on default settings.

_ resfiles are a list of .RES files to bind to the executable.

TLINK assumes or appends these extensions to file names that have none:

_ .OB] for object files _ .LIB for library files _ .EXE for executable files

_ .DLL for dynamic-link libraries _ .MAP for map files

_ .DEF for module-definition files

_ .RES for resource files TLINK uses a configuration file called TLINK.CFG (or TLINK32.CFG) for options that you'd normally type at the command-line (note that

TLINK.CFG can only be options, not file names). Configuration files let you save options you use frequently, so that you don't have to continually retype them.

TLINK looks for TLINK.CFG in the current directory, then in the directory from which TLINK was loaded.

The following TLINK.CFG file tells TLINK to look for libraries first in the directory C: \ BC4 \ LIB and then in C: \ WINAPPS \ LIB, to include debug

Borland C++ Users Guide

Response files The command-line compilers also use response files. See page 45 for more information.

information in the executables it creates, to create a detailed segment map, and to produce a Windows executable (.EXE not .DLL).

TLINK TLINK32

ILC:\bc4\libic:\winapps\lib Iv Is

ITwe

ILc:\bc4\libi c:\winapps\lib Iv Is

ITpe

Response files are ASCII files of options and file names for TLINK.EXE (and TLINK32.EXE) that you would normally type at the command line.

Response files let you have a longer command line than most operating systems allow. Response files can include the same information as configuration files (command-line options), but they can also contain file names.

Unlike the command line, a response file can be several lines long. To use more than one line in your response file, end each line with a plus character (+). Note that if a line ends with an option that uses the plus to turn it on (such as /v+), the + isn't treated as a line continuation character (to continue the line, use Iv++).

If you separate command-line components (such as .OBJ files from .LIB files) by lines in a response file, you must leave out the comma used to separate them on the command line. For example,

Ic cOWSt

rnyprog,rnyexe rnyrnap rnylib cws

leaves out the commas you'd have to type if you put the information on the command line:

TLINK Ic cOws rnyprog,rnyexe,rnyrnap,rnylib cws To use response files,

1. Type the command-line options and file names into an ASCII text file and save the file.

2. Type TLINK @[path]RESFILE.RSP, where RESFILE.RSP is the name of your response file.

You can specify more than one response file as follows:

tlink Ic @listobjs,rnyexe,rnyrnap,@listlibs

If you use a response file in addition to command-line options, the command-line options will override any options in the response file. For

Using TLiNK with command-line, TLINK uses the command-line option -v-.

You can pass options and files to TLINK through the command-line compilers (BCC.EXE and BCC32.EXE) by typing file names on the com-mand line with explicit .OBJ and .LIB extensions. For example,

BCC mainfile.obj subl.obj mylib.lib

links MAINFILE.OBJ, SUBl.OBJ, and MYLIB.LIB and produces the executable MAINFILE.EXE.

BCC starts TLINK with the files COWS.OBJ, CWS.LIB, and IMPORT. LIB (initialization module, run-time library, and Windows import library).

BCC32 starts TLINK32 with the files COW32.0BJ, CW32.LIB, and IMPORT32.LIB by default.

You must always link the Borland C++ run-time library that contains the standard C/C++ library functions for the type of application you are linking. You must also include the appropriate import library (IMPORT. LIB for 16-bit Windows applications,IMPORT32.LIB for console applications, ' or IMPRTW32.LIB for 32-bit Windows applications).

Table 9.1 describes the 16-bit Windows 3.~ libraries and .OBJ files provided by Borland. See the Library Reference for a complete list of Windows

libraries and the DOS Reference for a complete list of DOS libraries and startup files. indicate Small, Compact, Medium, Large or Huge memory model.

Run-time library for Windows 3.x applications, where n is S, C, M, or L to indicate Small, Compact, Medium, or Large memory model.

Run-time library for Windows 3.x applications to link in as a .DLL.

Import library for Windows 3.x API functions.

Startup code for DOS .EXE applications, where n is T, S, C, M, L, or H to indicate Tiny, Small, Compact, Medium, Large or Huge memory model.

Startup code for Windows 3.x applications, where n is S, M, C, or L to indicate Small, Medium, Compact, or Large memory model.

Startup code for Windows 3.x .DLL modules, where n is S, M, or L to indicate Small, Medium, or Large memory model.

If your program uses floating-paints, you must include a math library.

MATHWS.LlB is for small and tiny models.

Math library for compact models.

Borland C++ Users Guide

Table 9.2 Borland 32-bit libraries and startup files

Table 9.1: Borland 16-bit libraries and startup files (continued) MATHWM.LlB Math library for medium models.

MATHWL.LlB Math library for large models.

Table 9_2 describes the 32-bit libraries and .OBJ files provided by Borland;

these are used by TLINK32. See the Library Reference for a complete list of libraries.

Libraries and .OBJs CW32.LlB

. IMPORT32.LlB COX32.0BJ COW32.0BJ COD32.0BJ

Description

Run-time library for Win32 applications. .

Import library for console applications and 32-bit Windows applications.

Startup code for console applications.

Startup code for Win32 applications.

Startup code for 32-bit DLL modules.

Im Dokument or an (Seite 156-160)