LinuxCommandLibrary

dmd

Compile D programming language source code

TLDR

Build a D source file

$ dmd [path/to/source.d]
copy

Generate code for all template instantiations
$ dmd -allinst
copy

Control bounds checking
$ dmd -boundscheck=[on|safeonly|off]
copy

List information on all available checks
$ dmd -check=[h|help|?]
copy

Turn on colored console output
$ dmd -color
copy

SYNOPSIS

dmd [options] source-files

PARAMETERS

-c
    Compile only; do not link into executable.

-conf=file
    Use dmd.conf configuration file.

-debug
    Compile in debug mode (disable optimizations, enable asserts).

-g
    Generate debug information for GDB.

-H
    Generate header file (.di) for each source.

-I=path
    Add path to import search directories.

-J=path
    Add path to version import search directories.

-L=flag
    Pass linker flag to the linker.

-lib
    Generate static library instead of executable.

-of=name
    Set output file/library name to name.

-od=dir
    Write object files to directory dir.

-op=dir
    Write executable/library to directory dir.

-O
    Optimize generated code.

-release
    Compile release version (no debug checks).

-run
    Run resulting program after building, passing remaining args.

-shared
    Generate dynamic (shared) library.

-unittest
    Enable unit tests.

-v
    Verbose output.

-version
    Print compiler version and exit.

-wi
    Enable warnings as errors.

DESCRIPTION

DMD is the official reference compiler for the D programming language, developed by Walter Bright at Digital Mars. It compiles D source code (.d files) into efficient native executables, object files, or libraries for Linux, among other platforms. Renowned for its exceptional compilation speed, DMD supports advanced D features like templates, mixins, contracts, ranges, and garbage collection via the Druntime and Phobos standard libraries.

DMD offers incremental compilation, profile-guided optimization, and integrated unit testing. It traditionally used its own backend but switched to LLVM backend by default for better code generation on modern architectures. Command-line driven, it's ideal for scripting, systems programming, and large projects.

Basic usage: dmd hello.d produces hello executable. Supports modules, conditional compilation, and cross-compilation. Pair with rdmd for dependency handling or dub for builds. Requires Druntime/Phobos installed; not standard on most distros.

CAVEATS

Not installed by default; requires Druntime/Phobos. Uses LLVM backend on x86_64 Linux (legacy available via -m). Configured via dmd.conf. Large projects may need dub package manager.

INSTALLATION

Download binaries from dlang.org/download or install via apt (dmd, libphobos2-dev) on Ubuntu/Debian.

CONFIG FILE

dmd.conf auto-loaded from bin/, etc., sets default -L linker flags like -defaultlib=phobos2.

BACKENDS

LLVM (--llvm default); legacy DMD (-m) for compatibility.

HISTORY

Released 2004 by Digital Mars (Walter Bright). D Foundation took over 2014. LLVM backend default since DMD 2.100+ (2022), improving optimizations/portability. Actively developed for D2.x evolution.

SEE ALSO

rdmd(1), dub(1), gcc(1), ld(1), llvm-ar(1)

Copied to clipboard