Share via


Module-Definition File (Compact 2013)

3/26/2014

A module-definition (.def) file is a text file which contains statements defining the public symbols, functions and variables, that are exported from an executable file. The executable file is typically a dynamic-link library (DLL).

Although all executable files can use .def files, they are mainly used by the linker tool to define the functions exported by DLLs.

The statements in a .def file provide the linker with information about exports, attributes, and other information about the application to be linked.

Most statements appear once in the .def file, and accept one specification of arguments, which follows the statement keyword on the same or subsequent lines.

If you repeat the statement with different arguments later in the file, the later statement overrides the earlier one. Many of these statements have an equivalent LINK command-line option.

The SECTIONS, EXPORTS, and IMPORTS statements can appear more than once in the .def file. Each statement can take multiple specifications, which must be separated by one or more spaces, tabs, or newline characters.

The statement keyword must appear once before the first specification, and it can be repeated before each additional specification.

A semicolon at the beginning of each comment line designates comments in the .def file. A comment cannot share a line with a statement, but it can appear between specifications in a multiline statement, such as SECTIONS and EXPORTS.

If a string argument matches a reserved word, it must be enclosed in double quotation marks.

Numeric arguments are specified in decimal or C-language notation.

NAME

This statement specifies a name for the main output file, and it must precede all other statements.

The statement syntax is as follows:

NAME[application][BASE=address]

Remarks

In LINK, You can specify an output filename with the Output File Name (/OUT) option and set the base address with the Base Address (/BASE) option.

If both NAME and /OUT are specified, /OUT overrides NAME.

EXPORT

This statement makes one or more definitions available as exports to other applications.

The statement uses the following syntax:

EXPORTS definitions

This statement makes one or more definitions available as exports to other applications. When LINK builds an application that contains exports, it also creates an import library, unless an .exp file is used in the build.

EXPORTS marks the beginning of a list of export definitions. The EXPORTS keyword can be on the same line as the first definition or on a preceding line, but each definition must be on a separate line. A .def file can contain one or more EXPORTS statements.

An export definition uses the following syntax:

entryname[=internalname] [@ordinal[NONAME]] [DATA] [PRIVATE]

Remarks

The optional keyword PRIVATE prevents entryname from being placed in the import library that LINK generates. However, it has no effect on the export in the run-time image that LINK also generates.

There are three methods for exporting a definition, listed in recommended order of use:

  1. The __declspec(dllexport) keyword in the source code
  2. An EXPORTS statement in a .def file
  3. An /EXPORT specification in a LINK command

All three methods can be used in the same application.

LIBRARY

This statement tells LINK to create a DLL and must precede all statements when used. At the same time, LINK creates an import library, unless an export (.exp) file is used in the build.

The statement syntax is as follows:

LIBRARY [library][BASE=address]

Remarks

The LIBRARY argument specifies the internal name of the DLL. In LINK, you use the Output File Name (/OUT) option to specify the DLL's output name.

The BASE=address argument sets the base address that the operating system uses to load the DLL. This argument overrides the default DLL location of 0x10000000. For more information about base addresses, see the Base Address (/BASE) option.

In LINK, you can specify a DLL build with the /DLL option, and set the base address with the /BASE option.

DESCRIPTION

This statement writes a string into an .rdata section, and uses the following syntax:

DESCRIPTION "text"

Remarks

You enclose the specified text in single or double quotation marks. To use a literal quotation mark in the string, enclose the string with the other type of quotation mark.

This functionality differs from the comment that you specify in LINK with the /COMMENT option.

STACKSIZE

This statement sets the size of the stack in bytes. You can set the stack in LINK with the Stack Allocations (/STACK) option.

The statement uses the following syntax:

STACKSIZE reserve[,commit]

Remarks

This option has no effect on DLLs because the stack size only affects the default stack size for the process.

SECTIONS

This statement sets attributes for one or more sections in the run-time image. You can use it to override the default attributes for each section type.

The statement uses the following syntax:

SECTIONS definitions

The SEGMENTS keyword is supported as a synonym for SECTIONS.

SECTIONS marks the beginning of a list of section definitions. The SECTIONS keyword can be on the same line as the first definition or on a preceding line, but each definition must be on a separate line.

A .def file can contain one or more SECTIONS statements.

The syntax for a section definition is:

section [CLASS 'classname'] attributes

Remarks

The section name is case sensitive. The CLASS keyword is supported for compatibility, but is ignored. The attributes are one or more of the following: EXECUTE, READ, SHARED, and WRITE.

In LINK, you can specify section attributes with the /SECTION option.

VERSION

This statement tells LINK to put a number in the header of the .exe file or DLL.

The statement uses the following syntax:

VERSION major[.minor]

Remarks

The major and minor arguments are decimal numbers in the range 0 through 65,535. The default setting is 0.0.

In LINK, you can specify a version number with the Version Information (/VERSION) option.

See Also

Reference

Build Tool (Build.exe)