GDC(1)
π¦ GDC(1) β GNU's gdc, the GCC-based compiler for the D language π¦
β¨ NAME β¨
gdc β a GCC-based compiler for the D language. That's the whole main-character energy of this page, bestie. π
π 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 remainder.
π DESCRIPTION π
The gdc command is the GNU compiler for the D language, and it supports many of the same options as gcc. This manual is specifically here to document the options that are specific to gdc β iykyk. β¨
π OPTIONS π
π Input and Output files π
For any given input file, the file name suffix determines what kind of compilation gets done. The following kinds of input file names are supported:
file.dβ D source files.file.ddβ Ddoc source files.file.diβ D interface files.
You can specify more than one input file on the gdc command line, and each one is 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. Slay. π«Ά
A D interface file contains only what an import of the module needs, rather than the whole implementation of that module. gdc can create them 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.
A Ddoc source file contains code in the D macro processor language. It's 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's treated as general purpose documentation, not as a D source file. π
β‘ Runtime Options β‘
These options affect the runtime behavior of programs compiled with gdc. Let's get into it. π₯
-fall-instantiationsβ generates 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.-fno-assertβ turns off code generation forassertcontracts.-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's safe to use this option if you're sure your code never throws aRangeError.-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 recognizes when a function in thecore.stdcpackage is a built-in function.-fcheckaction=valueβ controls what code is generated on an assertion, bounds check, or final switch failure. The following values are supported:contextβ throws anAssertErrorwith extra context information.haltβ halts the program execution.throwβ throws anAssertError(the default).
-fdebug,-fdebug=valueβ turns on compilation of conditionaldebugcode into the program. The-fdebugoption itself sets the debug level to1, while-fdebug=enablesdebugcode identified by any of the following values:identβ turns on compilation of anydebugcode identified by ident.
-fno-druntimeβ implements<https://dlang.org/spec/betterc.html>. It 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β includes 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, because it lets you run 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 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.-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β implements<https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md>(Scoped pointers).dip1008β implements<https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1008.md>(Allow exceptions in@nogccode).dip1021β implements<https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md>(Mutable function arguments).dip25β implements<https://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.
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β reverts<https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md>(Scoped pointers).dip25β reverts<https://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.-fno-switch-errorsβ 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:
-Idirβ bestie, this is the "look here for imported modules at compile time" flag π You can stack as many-Ioptions as you want, and the paths get searched in the same order you gave them.-Jdirβ same vibe but for string imports: it tells the compiler where to look for files inimport(file)expressions at compile time π This switch is required if you want to useimport(file)at all, no cap. Multiple-Joptions can be used, and the paths are searched in the same order.-Ldirβ when linking, specify a library search directory, exactly like you'd do withgccβ¨-Bdirβ this one tells the compiler where to find its own executables, libraries, source files, and data files, as withgccπ«Ά-fmodule-file=module=specβ okay so this is the module path remix π§ It messes with file paths of imported modules: if an imported module matches all (or the leftmost part) of module, then the file path in spec is used as the location to search for D sources. Use it when your source file paths and names don't line up with your package/module hierarchy. Lowkey essential. Consider these examples:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
This tells 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, like this D code is annotated:
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β use dir as a subdirectory of the gcc directory that contains target-specific D sources and interfaces πΈ-iprefix prefixβ specify prefix as the prefix for the gcc directory containing target-specific D sources and interfaces. Real talk: if the prefix represents a directory, you gotta include the final/π―-nostdincβ do NOT search the standard system directories for D source and interface files. Only the directories you specified with-Ioptions (and the directory of the current file, if appropriate) get searched. Independent icon behavior π
β¨ Code Generation β¨
On top of the many gcc options controlling code generation, gdc has several options that are specific to itself π§
-Hβ generates D interface files for all modules being compiled. The compiler figures out the output file from the name of the input file: strip any directory components and the suffix, then slap.dion it π-Hd dirβ same as-H, but writes interface files to directory dir. You can pair this with-Hf fileso the output file and directory path are set independently.-Hf fileβ same as-Hbut writes interface files to file. Pair it with-Hd dirto independently set the output file and directory path π«Ά-Mβ outputs 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 π-MF fileβ when used with-Mor-MM, specifies a file to write the dependencies to. And when used with the driver options-MDor-MMD,-MFoverrides the default dependency output file. Multitasking icon β¨-MGβ this option exists for compatibility with gcc, and the compiler just ignores it. It's giving "I'm here for moral support" π-MPβ outputs a phony target for each dependency other than the modules being compiled, which makes each of them depend on nothing.-MT targetβ changes the target of the rule emitted by dependency generation to be exactly the string you specify. Need multiple targets? Pass them as a single argument to-MT, or just use multiple-MToptions π€-MQ targetβ same as-MT, but it quotes any characters that are special tomake. Considerate queen π-MDβ equivalent to-M -MF file. The driver determines file by removing any directory components and suffix from the input file, then adding a.depssuffix π-MMDβ like-MDbut does not mention imported modules from the D standard library package directories.-Xβ outputs information describing the contents of all source files being compiled, in JSON format, to a file. The driver determines file by stripping any directory components and suffix from the input file, then adding a.jsonsuffix π-Xf fileβ same as-X, but writes all the JSON contents to the specified file.-fdocβ generates "Ddoc" documentation and writes it to a file. The compiler determines file by removing any directory components and suffix from the input file, then adding an.htmlsuffix π-fdoc-dir=dirβ same as-fdoc, but writes documentation to directory dir. Pair with-fdoc-file=fileto independently set the output file and directory path.-fdoc-file=fileβ same as-fdoc, but writes documentation to file. Pair with-fdoc-dir=dirto independently set the output file and directory path π-fdoc-inc=fileβ specifies file as 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 the corresponding C++ declarations in file. C++ crossover episode π-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 to file. Super useful for debugging compilation errors, and it gives debuggers source to show when asked π₯
π Warnings π
Warnings are diagnostic messages reporting constructions that are not inherently erroneous but are risky, or that suggest there's likely a bug in the program. Unless -Werror is specified, they do not prevent compilation of the program π«Ά
-Wallβ turns on all warning messages. Warning: 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β warns on all uses ofallocain the source.-Walloca-larger-than=nβ warns on unbounded uses ofalloca, and on bounded uses ofallocawhose bound can be larger than n bytes. Meanwhile-Wno-alloca-larger-thandisables the-Walloca-larger-thanwarning and is equivalent to-Walloca-larger-than=SIZE_MAXor larger π―-Wno-builtin-declaration-mismatchβ warns if a built-in function is declared with an incompatible signature. Ngl that's a red flag behavior and it will be flagged π-Wcast-resultβ warns 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 withdeprecatedattributes. Let the past be the past, bestie π-Werrorβ turns all warnings into errors. Main character energy, zero tolerance β-Wextraβ enables some extra warning flags that are not enabled by-Wall. The lineup:-Waddress-Wcast-result-Wmismatched-special-enum-Wunknown-pragmas
-Wmismatched-special-enumβ warns when an enum the compiler recognizes as special is declared with a different size than the built-in type it's representing π-Wspeculativeβ lists all error messages from speculative compiles, like__traits(compiles, ...). Heads up: this option does not report messages as warnings, so these messages therefore never become errors even when-Werroris also used β οΈ-Wunknown-pragmasβ warns when apragma()is encountered that is not understood bygdc. And this differs from-fignore-unknown-pragmas: there, a pragma that's 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 bestie: this option is now deprecated and will be removed in a future release π-fmax-errors=nβ limits the maximum number of error messages to n, at which pointgdcbails out instead of trying to keep processing the source code. If n is0(the default), there's no limit on how many error messages get produced π-fsyntax-onlyβ checks the code for syntax errors, but does not actually compile it. You can use it alongside-fdocor-Hto generate files for each module present on the command-line, but no other output file gets made π¦-ftransition=idβ reports additional information about D language changes identified by id. The supported values: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. Real talk: they're meaningless if the compiler isn't doing a link step π«₯
-defaultlib=libnameβ specifies the library to use instead oflibphoboswhen linking. Options that specify the linkage oflibphobos, like-static-libphobosor-shared-libphobos, get ignored π-debuglib=libnameβ specifies the debug library to use instead oflibphoboswhen linking. Heads up: 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, like-static-libphobosor-shared-libphobos, are ignored. The standard system libraries are used normally, unless-nostdlibor-nodefaultlibsis used πΈ-shared-libphobosβ on systems that providelibgphobosandlibgdruntimeas both 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β bestie, when your system shipslibgphobosandlibgdruntimeboth as a shared and a static library, this lil flag forces the static one to be the one you use π . Key caveat tho: if no static version was built when the compiler was configured, this option just... does nothing. No effect. Zero. Nada. π
β¨ Developer Options β¨
Okay so this next cluster is for the devs and the language-tooling girlies β primarily of interest to developers or language tooling, as the ancients say π§. If you're just out here writing D code, you can vibe-check right past this. But if you're poking at the compiler's insides? Welcome, this is your era π
-fdump-d-originalβ dumps out the internal front-end AST after the"semantic3"stage πΈ. Real talk though: this one is only useful for debugging the GNU D compiler itself. It's not a you-and-your-code tool, it's a looking-inside-the-machine tool π₯.-vβ the gossip flag π. It dumps info about the compiler's language processing stages as your source program is being compiled. Specifically it gives you:- a listing of all modules processed through the
"parse","semantic","semantic2", and"semantic3"stages π - all
"import"modules and their file paths π¦ - all
"function"bodies that are being compiled π
- a listing of all modules processed through the
It's giving "tell me everything, I want the whole group chat" and honestly? Iconic.
π SEE ALSO
Go read these too, they're the supporting cast and they ate:
gpl(7)gfdl(7)fsf-funding(7)gcc(1)- and the Info entries for
gdcandgccβ
π COPYRIGHT
Copyright (c) 2006-2025 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) π«Ά
And that's the whole page, bestie β no cap, we made it π. This masterpiece is stamped gcc-15, dated 2026-06-12, and lives its best life as GDC(1). Periodt. π
π¦ where this page comes from
- opensuse-leap 16.0: gcc15-d 15.3.0+git11272-160000.2.1 Β· GPL-3.0-or-later
- opensuse-leap 16.0: gcc15-d 15.3.0+git11272-160000.2.1 Β· GPL-3.0-or-later
- opensuse-leap 16.0: gcc15-d 15.3.0+git11272-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