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] files... [-o output_file]
gdc [-std=version] [-I import_path] [-L library_path] [-l library] [-Olevel] [-g] [-c] source_file.d [-o executable]
PARAMETERS
-o <file>
Specify the output file name.
-c
Compile or assemble the source files, but do not link.
-S
Compile only; do not assemble or link.
-E
Preprocess only; do not compile, assemble, or link.
-Wall
Enable all common warnings.
-O<level>
Set optimization level (e.g., -O2, -O3, -Os).
-g
Generate debugging information for debuggers like GDB.
-std=<version>
Specify the D language standard to use (e.g., d2).
-I<dir>
Add directory to the D import search path.
-L<dir>
Add directory to the library search path for linking.
-l<lib>
Link with the specified library.
-fPIC
Generate position-independent code for shared libraries.
-shared
Create a shared library.
-fcheck-contract
Enable all D language contract checks (asserts, in/out, invariants).
-fdoc
Generate Ddoc documentation files.
DESCRIPTION
gdc is the GNU D compiler, a frontend for the D programming language integrated into the GNU Compiler Collection (GCC). It allows developers to compile D source code into executables, shared libraries, or static libraries. gdc leverages GCC's robust backend, providing optimized code generation, support for multiple architectures, and integration with the wider GCC toolchain.
It supports various D language features and standards, enabling the creation of high-performance and reliable applications. Like other GCC frontends, gdc accepts a wide array of standard GCC options for optimization, debugging, linking, and warning control, alongside D-specific options for language versioning, contract checking, and module management. Its presence within GCC makes it a strong contender for D development on Linux and other GCC-supported platforms.
CAVEATS
gdc's behavior is heavily dependent on the GCC version it's built against. Newer GCC versions might offer better D language feature support or optimizations. Not all D language features, especially very recent ones from the D Language Specification, might be fully implemented or optimized in older gdc versions. Compatibility with specific D runtime libraries might also vary.
D LANGUAGE INTEGRATION
gdc provides seamless integration for compiling D source files (.d or .di) within a mixed-C/C++ project environment. It can compile D code and link it with object files or libraries generated by other GCC frontends.
RUNTIME LIBRARY
gdc typically uses libphobos, the D standard library implementation for gdc, along with libdruntime, the D runtime library. These are crucial for D applications to function correctly, providing garbage collection, concurrency primitives, and other core functionalities.
HISTORY
The D language compiler frontend for GCC, gdc, began development in the early 2000s by David Friedman and others, aiming to integrate D into the robust GNU Compiler Collection ecosystem. This integration allowed D to benefit from GCC's established optimization passes, multi-platform support, and extensive tooling. While not the first D compiler (DMD by Walter Bright predates it), gdc offered an open-source, GCC-native alternative, appealing to developers already reliant on the GNU toolchain. Its development has progressed alongside GCC's releases, often adding support for new D language features and improving performance, ensuring D's presence within the broader open-source compiler landscape.