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
Key Facts
- .def files were introduced as the standard DLL export mechanism with Windows 3.0 release in May 1990
- A single .def file can manage exports for up to 65,536 functions per DLL using ordinal numbers (1-65535)
- The EXPORTS section in .def files is mandatory and must explicitly list every symbol accessible to external programs
- Microsoft's linker (link.exe) processes .def files during compilation to generate the DLL's export address table
- .def files can reduce DLL binary size by 5-15% when using ordinal-based exports instead of function names
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.
- EXPORTS Section: This mandatory section lists all functions and variables that should be available to programs using the DLL, with each export on a new line. Each entry can include the symbol name, an optional ordinal number (a numeric identifier between 1 and 65535), and export modifiers like NONAME or DATA.
- LIBRARY Declaration: An optional section that specifies the DLL's internal name, helping the linker organize internal references and providing metadata to external tools that read the DLL's structure.
- Ordinal Numbers: Each exported symbol can be assigned a unique ordinal number, allowing programs to call functions by number instead of name. This approach reduces the final DLL size and can provide minor performance benefits for calling code seeking specific symbols.
- Import/Export Data: The .def file can specify which symbols are data (variables) versus functions, with the DATA keyword explicitly marking variable exports. This distinction helps the linker properly configure memory access and relocation information.
- Version Information: Advanced .def files can include VERSION statements to document API compatibility versions, helping developers track which versions of an exported API are stable or deprecated across releases.
Key Comparisons
| Aspect | .def File Method | __declspec(dllexport) | Module Definition |
|---|---|---|---|
| Location | Separate text file in project directory | Directly in C/C++ header or source code | Implicit in source code decorators |
| Ease of Use | Requires separate file management and linker configuration | Simple inline syntax, minimal configuration needed | Centralized control with explicit ordinals |
| Backward Compatibility | Excellent; supports ordinal-based exports for version stability | Good; works across modern compiler versions | Best for legacy Windows 3.x/95 compatibility |
| File Size Reduction | Significant when using ordinal exports instead of names | Minimal impact unless combined with optimization | Variable based on export strategy |
| Ordinal Support | Full support for numeric export identifiers | Limited support without additional configuration | Primary mechanism in legacy systems |
Why It Matters
- API Control: .def files provide explicit, centralized control over what constitutes the public API of a DLL, preventing accidental exposure of internal functions or data that should remain private.
- Binary Compatibility: Ordinal-based exports maintain binary compatibility across DLL versions, allowing updated libraries to be deployed without recompiling dependent applications.
- Performance Optimization: Using ordinal numbers instead of function names can reduce export table size by 5-15% and provide faster function resolution in performance-critical applications.
- Legacy System Support: Many Windows systems and applications built before modern export mechanisms remain in use; .def files ensure these systems continue to function correctly across decades of operating system updates.
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.
More What Is in Daily Life
Also in Daily Life
More "What Is" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- Microsoft: Exporting from a DLLCC-BY-4.0
- Microsoft: Module-Definition (.def) FilesCC-BY-4.0
- Wikipedia: Dynamic-link libraryCC-BY-SA-4.0
Missing an answer?
Suggest a question and we'll generate an answer for it.