gdc
Compile D programming language code
TLDR
Create an executable
Print information about module dependencies
Generate Ddoc documentation
Generate D interface files
Do not link the standard GCC libraries in the compilation
SYNOPSIS
gdc [options...] input.d [input.d...]
PARAMETERS
-o file
Specify output file name
-c
Compile to object file only
-S
Compile to assembly file
-E
Preprocess only
-g
Generate debug info
-O[level]
Optimization level (0-3, default 1)
-Wall
Enable all warnings
-Werror
Treat warnings as errors
-Idir
Add import directory
-Jpath
Look for module files in path
-Ldir
Add library search directory
-llib
Link library
-shared
Generate shared library
-fPIC
Generate position-independent code
-version=X
Enable version identifier X
-debug=X
Enable debug identifier X
-funittest
Enable unittests
-fcheck-all
Enable all runtime checks
-main
Generate main() function
-v
Verbose output
DESCRIPTION
The gdc command is the GNU D Compiler, a frontend for the GCC compiler suite specifically designed to compile code written in the D programming language. D is a general-purpose systems programming language with C-like syntax, offering modern features like contract programming, garbage collection, and compile-time function execution.
gdc leverages the GCC backend for code generation, optimization, and support for multiple architectures. It compiles D source files (.d) into object files or executables, handling modules, imports, templates, and mixins. Key strengths include seamless C/C++ interoperability via extern(C), high performance optimizations matching GCC, and integration with GNU tools like binutils and glibc.
Usage involves specifying input .d files and options for compilation modes (e.g., -c for objects, -shared for libraries). D-specific flags control versioning, debugging levels, unittests, and bounds checking. Output defaults to <input>.o or a.out, customizable with -o. It supports preprocessor directives and conditional compilation based on versions and debug statements.
gdc is ideal for Linux/Unix environments, producing position-independent code and static/dynamic libraries. It requires the D runtime library (druntime) and Phobos standard library, often linked automatically.
CAVEATS
gdc requires GCC 10+ and druntime/Phobos; some D features may differ from reference DMD compiler. Not all GCC options are fully supported for D.
EXIT STATUS
0 on success, non-zero on error (e.g., 1 for compile failure, 4 for warnings-as-errors).
EXAMPLES
gdc -O2 -Wall hello.d -o hello
gdc -shared -o libfoo.so foo.d
HISTORY
Developed in 2004 by David Friedman as GCC frontend for D 1.0. Evolved with D 2.0 support; maintained by D Language Foundation since 2012. Integrated into GCC officially from version 4.6 (experimental), mature in GCC 9+.


