GDC(1)
๐ธ NAME ๐ธ
gdc โ a GCC-based compiler for the D language, bestie. This is the GNU GDC(1) manual page, and it's literally the main character for compiling D with GCC energy.
โจ SYNOPSIS โจ
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
Only the most useful options are listed here โ see below for the rest.
๐ DESCRIPTION ๐
The gdc command is the GNU compiler for the D language and supports many of the same options as gcc. This manual only documents the options specific to gdc, so no cap: it's the <pink>gdc-specific</pink> lore.
๐ OPTIONS ๐
๐ Input and Output files ๐
For any given input file, the file name suffix determines what kind of compilation is done. The following kinds of input file names are supported:
file.dโ D source files. Classic D energy.file.ddโ Ddoc source files. Documentation mode activated.file.diโ D interface files. The little import-friendly besties.
You can specify more than one input file on the gdc command line, each being compiled separately in the compilation process. If you specify a -o file option, all the input files are compiled together, producing a single output file, named file. This is allowed even when using -S or -c โ yes, even then. ๐
A D interface file contains only what an import of the module needs, rather than the whole implementation of that module. They can be created by gdc from a D source file by using the -H option. When the compiler resolves an import declaration, it searches for matching .di files first, then for .d. So .di gets first dibs, periodt.
A Ddoc source file contains code in the D macro processor language. It is primarily designed for use in producing user documentation from embedded comments, with a slight affinity towards HTML generation. If a .d source file starts with the string Ddoc then it is treated as general purpose documentation, not as a D source file. Cute, iconic, slightly chaotic. ๐
๐ Runtime Options ๐
These options affect the runtime behavior of programs compiled with gdc. Runtime vibes only.
-fall-instantiationsโ Generate code for all template instantiations. The default template emission strategy is to not generate code for declarations that were either instantiated speculatively, such as from__traits(compiles, ...), or that come from an imported module not being compiled. So this option is like "okay, compile everything, no holding back." ๐ฅ-fno-assertโ Turn off code generation forassertcontracts. Bye-bye assert codegen.-fno-bounds-checkโ Turns off array bounds checking for all functions, which can improve performance for code that uses arrays extensively. Note that this can result in unpredictable behavior if the code in question actually does violate array bounds constraints. It is safe to use this option if you are sure that your code never throws aRangeError. > โ ๏ธ That "unpredictable behavior" part is not a vibe, bestie โ only use this if you're truly sure.-fbounds-check=valueโ An alternative to-fbounds-checkthat allows more control as to where bounds checking is turned on or off. The following values are supported:onโ Turns on array bounds checking for all functions.safeonlyโ Turns on array bounds checking only for@safefunctions.offโ Turns off array bounds checking completely.
-fno-builtinโ Don't recognize built-in functions unless they begin with the prefix__builtin_. By default, the compiler will recognize when a function in thecore.stdcpackage is a built-in function. So this is the "no mysterious builtins unless they're wearing the__builtin_name tag" option.-fcheckaction=valueโ This option controls what code is generated on an assertion, bounds check, or final switch failure. The following values are supported:contextโ Throw anAssertErrorwith extra context information.haltโ Halt the program execution.throwโ Throw anAssertError(the default).
-fdebug,-fdebug=valueโ Turn on compilation of conditionaldebugcode into the program. The-fdebugoption itself sets the debug level to1, while-fdebug=enablesdebugcode that are identified by any of the following values:identโ Turns on compilation of anydebugcode identified by ident.
-fno-druntimeโ Implementshttps://dlang.org/spec/betterc.html. Assumes that compilation targets an environment without a D runtime library.
This is equivalent to compiling with the following options:
gdc -nophoboslib -fno-exceptions -fno-moduleinfo -fno-rtti
-fextern-std=standardโ Sets the C++ name mangling compatibility to the version identified by standard. The following values are supported:c++98,c++03โ Sets__traits(getTargetInfo, "cppStd")to199711.c++11โ Sets__traits(getTargetInfo, "cppStd")to201103.c++14โ Sets__traits(getTargetInfo, "cppStd")to201402.c++17โ Sets__traits(getTargetInfo, "cppStd")to201703. This is the default.c++20โ Sets__traits(getTargetInfo, "cppStd")to202002.c++23โ Sets__traits(getTargetInfo, "cppStd")to202302.
-finclude-importsโ Include imported modules in the compilation, as if they were given on the command line. When this option is enabled, all imported modules are compiled except those that are part oflibphobos.-fno-invariantsโ Turns off code generation for classinvariantcontracts.-fmainโ Generates a defaultmain()function when compiling. This is useful when unittesting a library, as it enables running the unittests in a library without having to manually define an entry-point function. This option does nothing whenmainis already defined in user code.-fno-moduleinfoโ Turns off generation of theModuleInfoand related functions that would become unreferenced without it, which may allow linking to programs not written in D. Functions that are not be generated include module constructors and destructors (static thisandstatic ~this),unittestcode, andDSOregistry functions for dynamically linked code.-fonly=filenameโ Tells the compiler to parse and run semantic analysis on all modules on the command line, but only generate code for the module specified by filename. Main character module only. โจ-fno-postconditionsโ Turns off code generation for postconditionoutcontracts.-fno-preconditionsโ Turns off code generation for preconditionincontracts.-fpreview=idโ Turns on an upcoming D language change identified by id. The following values are supported:allโ Turns on all upcoming D language features.bitfieldsโ Implements bit-fields in D.dip1000โ Implementshttps://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md(Scoped pointers).dip1008โ Implementshttps://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1008.md(Allow exceptions in@nogccode).dip1021โ Implementshttps://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md(Mutable function arguments).dip25โ Implementshttps://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md(Sealed references).dtorfieldsโ Turns on generation for destructing fields of partially constructed objects.fieldwiseโ Turns on generation of struct equality to use field-wise comparisons.fixaliasthisโ Implements new lookup rules that check the current scope foralias thisbefore searching in upper scopes.fiximmutableconvโ Disallows unsound immutable conversions that were formerly incorrectly permitted.inโ Implementsinparameters to meanscope const [ref]and accepts rvalues.inclusiveincontractsโ Implementsincontracts of overridden methods to be a superset of parent contract.nosharedaccessโ Turns off and disallows all access to shared memory objects.rvaluerefparamโ Implements rvalue arguments torefparameters.systemvariablesโ Disables access to variables marked@systemfrom@safecode.
-freleaseโ Turns on compiling in release mode, which means not emitting runtime checks for contracts and asserts. Array bounds checking is not done for@systemand@trustedfunctions, and assertion failures are undefined behavior. > โ ๏ธ Undefined behavior is giving "we're in the danger zone" โ release mode is not for the faint of heart.
This is equivalent to compiling with the following options:
gdc -fno-assert -fbounds-check=safe -fno-invariants \
-fno-postconditions -fno-preconditions -fno-switch-errors
-frevert=โ Turns off a D language feature identified by id. The following values are supported:allโ Turns off all revertable D language features.dip1000โ Revertshttps://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md(Scoped pointers).dip25โ Revertshttps://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md(Sealed references).dtorfieldsโ Turns off generation for destructing fields of partially constructed objects.intpromoteโ Turns off C-style integral promotion for unary+,-and~expressions.
-fno-rttiโ Turns off generation of run-time type information for all user defined types. Any code that uses features of the language that require access to this information will result in an error. So if your code needs RTTI, it's gonna be a whole thing. ๐ญ-fno-switch-errorsโ This option controls what code is generated when no case is matched in afinal switchstatement. The default run time behavior is to throw aSwitchError. Turning off-fswitch-errorsmeans that instead the execution of the program is immediately halted.-funittestโ Turns on compilation ofunittestcode, and turns on theversion(unittest)identifier. This implies-fassert.-fversion=valueโ Turns on compilation of conditionalversioncode into the program identified by any of the following values:identโ Turns on compilation ofversioncode identified by ident.
-fno-weak-templatesโ Turns off emission of declarations that can be defined in multiple objects as weak symbols. The default is to emit all public symbols as weak, unless the target lacks support for weak symbols. Disabling this option means that common symbols are instead put inCOMDATor become private.
๐ Options for Directory Search ๐
These options specify directories to search for files, libraries, and other parts of the compiler:
okay bestie, weโre still deep in option land โ hereโs the next batch, and yes every path matters ๐
-Idirโ tellsgdcwhich directory to use when searching for imported modules at compile time. You can stack multiple-Ioptions, and the paths are searched in the same order you give them. path order matters, bestie โจ-Jdirโ tellsgdcwhich directory to use when searching for files in string imports at compile time. This switch is required in order to useimport(file)expressions. Multiple-Joptions can be used, and the paths are searched in the same order. ๐-Ldirโ when linking, specify a library search directory, as withgcc. ๐-Bdirโ this option specifies where to find the executables, libraries, source files, and data files of the compiler itself, as withgcc. ๐ ๏ธ-fmodule-file=module=specโ this option manipulates file paths of imported modules, such that if an imported module matches all or the leftmost part ofmodule, the file path inspecis used as the location to search for D sources. This is used when the source file path and names are not the same as the package and module hierarchy. Consider the following examples:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
This will tell the compiler to search in all import paths for the source file foo.d when importing A.B, and the directory bar/ when importing C, as annotated in the following D code:
module test;
import A.B; // Matches A.B, searches for foo.d
import C.D.E; // Matches C, searches for bar/D/E.d
import A.B.C; // No match, searches for A/B/C.d
-imultilib dirโ usediras a subdirectory of the gcc directory containing target-specific D sources and interfaces. ๐๏ธ-iprefix prefixโ specifyprefixas the prefix for the gcc directory containing target-specific D sources and interfaces. If the prefix represents a directory, you should include the final'/'. donโt forget the slash, queen ๐-nostdincโ do not search the standard system directories for D source and interface files. Only the directories that have been specified with-Ioptions (and the directory of the current file, if appropriate) are searched. ๐ซ๐
๐ ๏ธ Code Generation ๐ ๏ธ
On top of the many gcc options controlling code generation, gdc has several options specific to itself. main character compiler energy ๐
-Hโ generates D interface files for all modules being compiled. The compiler determines the output file based on the name of the input file, removes any directory components and suffix, and applies the.disuffix. โจ-Hd dirโ same as-H, but writes interface files to directorydir. This option can be used with-Hf fileto independently set the output file and directory path. ๐-Hf fileโ same as-Hbut writes interface files tofile. This option can be used with-Hd dirto independently set the output file and directory path. ๐-Mโ output the module dependencies of all source files being compiled in a format suitable formake. The compiler outputs one make rule containing the object file name for that source file, a colon, and the names of all imported files. ๐ฆ-MMโ like-Mbut does not mention imported modules from the D standard library package directories. Same vibe, less noise. ๐ธ-MF fileโ when used with-Mor-MM, specifies a file to write the dependencies to. When used with the driver options-MDor-MMD,-MFoverrides the default dependency output file. ๐-MGโ this option is for compatibility withgcc, and is ignored by the compiler. itโs literally just vibing ๐-MPโ outputs a phony target for each dependency other than the modules being compiled, causing each to depend on nothing. ๐ป-MT targetโ change the target of the rule emitted by dependency generation to be exactly the string you specify. If you want multiple targets, you can specify them as a single argument to-MT, or use multiple-MToptions. ๐ฏ-MQ targetโ same as-MT, but it quotes any characters which are special tomake. ๐ง-MDโ this option is equivalent to-M -MF file. The driver determinesfileby removing any directory components and suffix from the input file, and then adding a.depssuffix. ๐๏ธ-MMDโ like-MDbut does not mention imported modules from the D standard library package directories. ๐-Xโ output information describing the contents of all source files being compiled in JSON format to a file. The driver determinesfileby removing any directory components and suffix from the input file, and then adding a.jsonsuffix. ๐งพ-Xf fileโ same as-X, but writes all JSON contents to the specifiedfile. โจ-fdocโ generates "Ddoc" documentation and writes it to a file. The compiler determinesfileby removing any directory components and suffix from the input file, and then adding a.htmlsuffix. ๐-fdoc-dir=dirโ same as-fdoc, but writes documentation to directorydir. This option can be used with-fdoc-file=fileto independently set the output file and directory path. ๐-fdoc-file=fileโ same as-fdoc, but writes documentation tofile. This option can be used with-fdoc-dir=dirto independently set the output file and directory path. ๐-fdoc-inc=fileโ specifyfileas a Ddoc macro file to be read. Multiple-fdoc-incoptions can be used, and files are read and processed in the same order. ๐-fdump-c++-spec=fileโ for D source files, generate corresponding C++ declarations infile. ๐-fdump-c++-spec-verboseโ in conjunction with-fdump-c++-spec=above, add comments for ignored declarations in the generated C++ header. ๐๏ธ-fsave-mixins=fileโ generates code expanded from D "mixin" statements and writes the processed sources tofile. This is useful to debug errors in compilation and provides source for debuggers to show when requested. ๐โจ
โ ๏ธ Warnings โ ๏ธ
Warnings are diagnostic messages that report constructions that are not inherently erroneous but that are risky or suggest there is likely to be a bug in the program. Unless -Werror is specified, they do not prevent compilation of the program. theyโre like little red flags, not full stops ๐ฉ
-Wallโ turns on all warnings messages. Warnings are not a defined part of the D language, and all constructs for which this may generate a warning message are valid code. ๐ฃ-Wallocaโ this option warns on all uses ofallocain the source. ๐ฌ-Walloca-larger-than=nโ warn on unbounded uses of alloca, and on bounded uses of alloca whose bound can be larger thannbytes.-Wno-alloca-larger-thandisables-Walloca-larger-thanwarning and is equivalent to-Walloca-larger-than=SIZE_MAXor larger. big number energy ๐ฅ-Wno-builtin-declaration-mismatchโ warn if a built-in function is declared with an incompatible signature. ๐งฉ-Wcast-resultโ warn about casts that will produce a null or zero result. Currently this is only done for casting between an imaginary and non-imaginary data type, or casting between a D and C++ class. ๐ญ-Wno-deprecatedโ do not warn about usage of deprecated features and symbols with "deprecated" attributes. ๐-Werrorโ turns all warnings into errors. no more warnings, bestie โ now theyโre crimes ๐-Wextraโ this enables some extra warning flags that are not enabled by-Wall:-Waddress,-Wcast-result,-Wmismatched-special-enum,-Wunknown-pragmas. โจ-Wmismatched-special-enumโ warn when an enum the compiler recognizes as special is declared with a different size to the built-in type it is representing. ๐ง-Wspeculativeโ list all error messages from speculative compiles, such as__traits(compiles, ...). This option does not report messages as warnings, and these messages therefore never become errors when the-Werroroption is also used. ๐-Wunknown-pragmasโ warn when apragma()is encountered that is not understood bygdc. This differs from-fignore-unknown-pragmaswhere a pragma that is part of the D language, but not implemented by the compiler, won't get reported. ๐ซถ-Wno-varargsโ do not warn upon questionable usage of the macros used to handle variable arguments likeva_start. ๐-fno-ignore-unknown-pragmasโ do not recognize unsupported pragmas. Anypragma()encountered that is not part of the D language will result in an error. > ๐จ heads up: this option is now deprecated and will be removed in a future release. donโt get attached, bestie ๐-fmax-errors=nโ limits the maximum number of error messages ton, at which pointgdcbails out rather than attempting to continue processing the source code. Ifnis0(the default), there is no limit on the number of error messages produced. ๐-fsyntax-onlyโ check the code for syntax errors, but do not actually compile it. This can be used in conjunction with-fdocor-Hto generate files for each module present on the command-line, but no other output file. ๐-ftransition=idโ report additional information about D language changes identified byid. The following values are supported:allโ list information on all D language transitions. ๐complexโ list all usages of complex or imaginary types. ๐ฎfieldโ list all non-mutable fields which occupy an object instance. ๐งฑinโ list all usages ofinon parameter. ๐ฅnogcโ list all hidden GC allocations. ๐๏ธtemplatesโ list statistics on template instantiations. ๐งฌtlsโ list all variables going into thread local storage. ๐งต
๐ Options for Linking ๐
These options come into play when the compiler links object files into an executable output file. They are meaningless if the compiler is not doing a link step. link oโclock, bestie ๐
-defaultlib=libnameโ specify the library to use instead oflibphoboswhen linking. Options specifying the linkage oflibphobos, such as-static-libphobosor-shared-libphobos, are ignored. ๐-debuglib=libnameโ specify the debug library to use instead oflibphoboswhen linking. This option has no effect unless the-goption was also given on the command line. Options specifying the linkage oflibphobos, such as-static-libphobosor-shared-libphobos, are ignored. ๐-nophoboslibโ do not use the Phobos or D runtime library when linking. Options specifying the linkage oflibphobos, such as-static-libphobosor-shared-libphobos, are ignored. The standard system libraries are used normally, unless-nostdlibor-nodefaultlibsis used. ๐ซ-shared-libphobosโ on systems that providelibgphobosandlibgdruntimeas a shared and a static library, this option forces the use of the shared version. If no shared version was built when the compiler was configured, this option has no effect. ๐ฆ-static-libphobosโ okay so on systems wherelibgphobosandlibgdruntimecome in both a shared and a static flavor, this flag makes the compiler pick the static one, periodt. But heads up: if no static version was built when the compiler was configured, this option literally does nothing. No effect, no drama, no notes. ๐
๐ ๏ธ Developer Options ๐ ๏ธ
This bit is all about the command-line options that are mostly for developers or for the language-tooling girlies โ the people poking at the compiler's insides. If that's not you, you can absolutely skip, but stay for the vibes anyway. ๐ซถ
-fdump-d-originalโ dumps out the internal front-end AST after thesemantic3stage. Not gonna lie, this one is only useful for debugging the GNU D compiler itself. It's giving "compiler surgeon only" energy, iykyk. ๐ฉบโจ-vโ this is the gossip flag, fr fr. It dumps information about the compiler's language processing stages while your source program is being compiled. What's in the dump? So much:- a listing of all modules processed through the
parse,semantic,semantic2, andsemantic3stages - all
importmodules, plus their file paths - all
functionbodies that are being compiled
- a listing of all modules processed through the
Basically the compiler narrating its own main character journey. Obsessed. ๐
๐ SEE ALSO ๐
Go check out gpl(7), gfdl(7), fsf-funding(7), gcc(1), and the Info entries for gdc and gcc. Bestie reading list, slay. ๐๐
๐ COPYRIGHT ๐
Copyright (c) 2006-2026 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the man page gfdl(7).
Fr fr, that's the actual license text โ keep it exactly as-is if you're passing this doc around. Respect the paperwork, it ate. ๐
and that's a wrap on the whole page, bestie!! ๐โจ This little masterpiece is from gcc-16, dated 2026-08-07, and it's living its best life as GDC(1). Go compile something iconic. ๐ฆ๐ธ๐
๐ฆ where this page comes from
- opensuse-leap 16.0: gcc16-d 16.2.0+git9497-160000.2.1 ยท GPL-3.0-or-later
- opensuse-leap 16.0: gcc16-d 16.2.0+git9497-160000.2.1 ยท GPL-3.0-or-later
- opensuse-leap 16.0: gcc16-d 16.2.0+git9497-160000.2.1 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms