What Is .def

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 10, 2026

Quick Answer: .def files are Windows definition files that specify which functions and variables from a Dynamic Link Library (DLL) should be exported, controlling external program access to compiled code. Introduced with Windows 3.0 in 1990, they remain a standard export mechanism in Windows development, allowing developers to assign ordinal numbers to symbols for backward compatibility and explicit API control. Modern projects can use .def files or the alternative __declspec(dllexport) syntax, depending on requirements for binary stability and legacy support.

Key Facts

Overview

.def files are plain text configuration files used in Windows programming to control what functions, variables, and other symbols get exported from a Dynamic Link Library (DLL). When developers compile a DLL in Windows, they need to specify which parts of their code should be accessible to external programs; this is where .def files come in. These files list exported symbols, assign them ordinal numbers, and define other export parameters that the Windows linker uses during compilation.

Originally introduced with the Windows 3.0 operating system in 1990, .def files became a standard mechanism for controlling DLL exports before modern alternatives like __declspec(dllexport) emerged. They remain widely used in legacy codebases and professional Windows development, particularly in projects that prioritize backward compatibility or require fine-grained control over exported symbols. The .def file format is simple, human-readable, and provides developers with explicit control over which library internals become part of the public API.

How It Works

A .def file operates by providing metadata to the Microsoft linker (link.exe) during the compilation and linking phase of DLL creation. The file contains several optional sections, with EXPORTS being the most critical for specifying what gets exposed to external code.

Key Comparisons

Aspect.def File Method__declspec(dllexport)Module Definition
LocationSeparate text file in project directoryDirectly in C/C++ header or source codeImplicit in source code decorators
Ease of UseRequires separate file management and linker configurationSimple inline syntax, minimal configuration neededCentralized control with explicit ordinals
Backward CompatibilityExcellent; supports ordinal-based exports for version stabilityGood; works across modern compiler versionsBest for legacy Windows 3.x/95 compatibility
File Size ReductionSignificant when using ordinal exports instead of namesMinimal impact unless combined with optimizationVariable based on export strategy
Ordinal SupportFull support for numeric export identifiersLimited support without additional configurationPrimary mechanism in legacy systems

Why It Matters

In modern Windows development, the choice between .def files and __declspec(dllexport) often depends on project requirements and legacy constraints. Large enterprise applications, system libraries, and projects requiring ordinal-based versioning continue to benefit from .def files' explicit control and backward compatibility guarantees. Understanding .def files remains valuable knowledge for Windows developers working with older codebases, commercial libraries, or systems requiring precise control over binary compatibility and API stability.

Sources

  1. Microsoft: Exporting from a DLLCC-BY-4.0
  2. Microsoft: Module-Definition (.def) FilesCC-BY-4.0
  3. Wikipedia: Dynamic-link libraryCC-BY-SA-4.0

Missing an answer?

Suggest a question and we'll generate an answer for it.