GDC(1)
๐ธ GDC(1) ยท GNU ๐ธ
๐ NAME ๐
okay so gdc is a GCC-based compiler for the D language ๐
that's literally it, bestie.
๐งพ SYNOPSIS ๐งพ
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
only the most useful options are shown up top โจ scroll down for the rest, there's a lot more ๐
๐ DESCRIPTION ๐
the gdc command is the GNU compiler for the D language ๐ฆ and it supports a lot of the same options as gcc, so if you already know gcc you're gonna feel right at home. this manual only covers the options that are specific to gdc ๐ซถ
๐ OPTIONS ๐
๐๏ธ Input and Output files
for any input file, the file name suffix decides what kind of compilation happens ๐ง these are the input file name kinds that are supported:
file.dโ D source files ๐file.ddโ Ddoc source files ๐file.diโ D interface files ๐
you can pass more than one input file on the gdc command line, and each one gets compiled separately ๐ฅ but if you use -o file, all the inputs get compiled together into one single output file named file. this works even with -S or -c ๐ญ
a D interface file only holds what an import of the module actually needs, not the whole implementation of that module, which is so smart โจ you can make one from a D source file with the -H option. when the compiler resolves an import declaration, it looks for matching .di files first, and only then goes looking for .d files ๐ฆ
a Ddoc source file has code written in the D macro processor language ๐
it's mostly for making user docs out of embedded comments, with a slight lean toward HTML output. if a .d source file starts with the string Ddoc, it gets treated as general purpose documentation instead of as D source ๐ธ
๐โโ๏ธ Runtime Options
these options change how programs compiled with gdc behave at runtime ๐
-fall-instantiationsโ generates code for every template instantiation ๐ the default strategy is to skip generating code for declarations that were instantiated speculatively (like from__traits(compiles, ...)) or that come from an imported module that isn't being compiled.-fno-assertโ turns off code generation forassertcontracts ๐-fno-bounds-checkโ turns off array bounds checking for all functions, which can boost performance for code that uses arrays a lot โก
โ ๏ธ this can cause unpredictable behavior if your code actually does break array bounds. it's only safe if you're totally sure your code never throws a RangeError ๐ญ
-fbounds-check=valueโ a more flexible alternative to-fbounds-checkthat lets you control where bounds checking is turned on or off ๐ the supported values are: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โ doesn't recognize built-in functions unless they start with the prefix__builtin_. by default, the compiler does recognize when a function in thecore.stdcpackage is a built-in function ๐ง-fcheckaction=valueโ controls what code gets generated when an assertion, bounds check, or final switch fails ๐ the supported values are:contextโ throws anAssertErrorwith extra context information ๐haltโ halts the program execution ๐throwโ throws anAssertError(this is the default) ๐
-fdebug,-fdebug=valueโ turns on compilation of conditionaldebugcode into the program ๐ the-fdebugoption by itself sets the debug level to 1, while-fdebug=enablesdebugcode identified by any of these values:identโ turns on compilation of anydebugcode identified byidentโจ
-fno-druntimeโ implements <https://dlang.org/spec/betterc.html> ๐ธ this assumes the compilation targets an environment with no D runtime library.
this is the same as 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 named bystandard๐ฆ the supported values are: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 is on, every imported module gets compiled except the ones that are part oflibphobos.-fno-invariantsโ turns off code generation for classinvariantcontracts ๐-fmainโ generates a defaultmain()function when compiling ๐ this is super handy when you're unittesting a library, since you can run its unittests without writing your own entry point. it does nothing ifmainis already defined in your user code ๐-fno-moduleinfoโ turns off generation of theModuleInfoand related functions that would become unreferenced without it, which may let you link to programs that aren't written in D ๐ฆ the functions that don't get 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 byfilename๐ง-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 byid๐ฎ the supported values are: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 @nogc code) ๐ฅ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 so it uses 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 used to be incorrectly permitted ๐inโ implementsinparameters to meanscope const [ref]and accepts rvalues ๐inclusiveincontractsโ implementsincontracts of overridden methods to be a superset of the 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 no runtime checks for contracts and asserts get emitted ๐ array bounds checking isn't done for@systemand@trustedfunctions, and assertion failures are undefined behavior.
โ ๏ธ assertion failures are undefined behavior in release mode, so be careful, bestie ๐ญ
this is the same as 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 byid๐ the supported values are: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 language features which need this info will throw an error.-fno-switch-errorsโ controls what code gets generated when no case matches in afinal switchstatement ๐ the default run time behavior is to throw aSwitchError. turning off-fswitch-errorsmeans the program instead halts immediately ๐-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 these values:identโ turns on compilation ofversioncode identified byident๐ธ
-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 doesn't support weak symbols. disabling this means common symbols get put in COMDAT or become private instead.
๐ Options for Directory Search
these options tell the compiler which directories to search for files, libraries, and other parts of the compiler ๐บ๏ธ
-Idir: ๐ Tell the compiler where to look for imported modules at compile time! You can use as many-Ioptions as you want, and they get searched in the order you wrote them.-Jdir: ๐ซถ This one points at where to search for files in string imports at compile time. You need this switch to useimport(file)expressions. Multiple-Joptions work too, and they're searched in order.-Ldir: ๐ When linking, add a library search directory, just like with gcc.-Bdir: ๐ง This tells gdc where to find the compiler's own executables, libraries, source files, and data files. Same deal as gcc.-fmodule-file=module=spec: โจ This one is kind of iconic. It messes with the file paths of imported modules. If an imported module matches all or the leftmost part ofmodule, the file path inspecbecomes the place to search for D sources. You'd use it when your source file paths and names don't match your package and module hierarchy. Check out these examples:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
This tells the compiler to search all import paths for the source file foo.d when importing A.B, and the directory bar/ when importing C. The comments in this D code show exactly what happens:
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: ๐ธ Usesdiras a subdirectory of the gcc directory that holds target-specific D sources and interfaces.-iprefix prefix: ๐ Setsprefixas the prefix for that same gcc directory with target-specific D sources and interfaces. If the prefix is a directory, make sure you include the final/.-nostdinc: ๐ Don't search the standard system directories for D source and interface files. Only the directories given with-Ioptions get searched, plus the directory of the current file if that's relevant.
โจ Code Generation โจ
In addition to the many gcc options controlling code generation, gdc has several options that are all its own ๐ .
-H: Generates D interface files for all modules being compiled. The compiler figures out the output file from the input file's name, strips any directory components and suffix, then adds the.disuffix.-Hd dir: Same as-H, but writes interface files to directorydir. You can pair it with-Hf fileto set the output file and directory path separately.-Hf file: Same as-H, but writes interface files tofile. You can pair it with-Hd dirto set the output file and directory path independently.-M: Outputs the module dependencies of all source files being compiled, in a format that works withmake. It writes one make rule with the object file name for that source file, a colon, and the names of all imported files.-MM: Like-M, but doesn't mention imported modules from the D standard library package directories.-MF file: When used with-Mor-MM, this says which file to write the dependencies to. When used with the driver options-MDor-MMD,-MFoverrides the default dependency output file.-MG: ๐ This one's just for compatibility with gcc. The compiler ignores it.-MP: Outputs a phony target for each dependency other than the modules being compiled, so each one depends on nothing.-MT target: Changes the target of the rule made by dependency generation to be exactly the string you specify. For 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 that are special to make.-MD: This is equivalent to-M -MF file. The driver figures outfileby removing directory components and suffix from the input file, then adding a.depssuffix.-MMD: Like-MD, but doesn't mention imported modules from the D standard library package directories.-X: Outputs info describing the contents of all source files being compiled, in JSON format, to a file. The driver figures out the file by removing 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 file you specify.-fdoc: Generates "Ddoc" documentation and writes it to a file. The compiler figures out the file by removing directory components and suffix from the input file, then adding a.htmlsuffix.-fdoc-dir=dir: Same as-fdoc, but writes documentation to directorydir. You can use it with-fdoc-file=fileto set the output file and directory path independently.-fdoc-file=file: Same as-fdoc, but writes documentation tofile. You can use it with-fdoc-dir=dirto set the output file and directory path independently.-fdoc-inc=file: Specifiesfileas a Ddoc macro file to be read. Multiple-fdoc-incoptions work, and the files get read and processed in the order given.-fdump-c++-spec=file: For D source files, generates the matching C++ declarations infile.-fdump-c++-spec-verbose: Used together with-fdump-c++-spec=above, this adds comments for ignored declarations in the generated C++ header.-fsave-mixins=file: ๐ Generates code expanded from Dmixinstatements and writes the processed sources tofile. This is super useful for debugging compile errors, and it gives debuggers source to show when requested.
๐จ Warnings ๐จ
Warnings are diagnostic messages about constructions that aren't inherently wrong, but are risky or suggest there's probably a bug in the program. Unless -Werror is specified, they don't stop the program from compiling.
-Wall: Turns on all warning messages. Warnings aren't a defined part of the D language, and all constructs that might generate a warning 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 thannbytes.-Wno-alloca-larger-thandisables-Walloca-larger-thanand 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.-Wcast-result: Warns about casts that will produce a null or zero result. Right now this only happens for casting between an imaginary and non-imaginary data type, or casting between a D and C++ class.-Wno-deprecated: Doesn't warn about usage of deprecated features and symbols withdeprecatedattributes.-Werror: ๐ Turns all warnings into errors.-Wextra: Enables some extra warning flags that are not enabled by-Wall:
-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 represents.-Wspeculative: Lists all error messages from speculative compiles, such as__traits(compiles, ...). This option doesn't report messages as warnings, so these messages never become errors, even when-Werroris also used.-Wunknown-pragmas: Warns when apragma()is encountered that gdc doesn't understand. This is different from-fignore-unknown-pragmas, where a pragma that is part of the D language but not implemented by the compiler won't get reported.-Wno-varargs: Doesn't warn about questionable usage of the macros used to handle variable arguments, likeva_start.-fno-ignore-unknown-pragmas: Doesn't recognize unsupported pragmas. Anypragma()encountered that is not part of the D language will result in an error. This option is deprecated and will be removed in a future release.
โ ๏ธ Heads up bestie: -fno-ignore-unknown-pragmas is deprecated and will be removed in a future release, so don't build your whole life around it ๐ฅบ.
-fmax-errors=n: Limits the maximum number of error messages ton, at which point gdc bails out instead of trying to keep processing the source code. Ifnis0(the default), there is no limit on the number of error messages produced.-fsyntax-only: Checks the code for syntax errors, but doesn't actually compile it. This can be combined with-fdocor-Hto generate files for each module on the command line, but no other output file.-ftransition=id: Reports additional information about D language changes identified byid. These 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 of "in" on 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're meaningless if the compiler isn't doing a link step.
-defaultlib=libname: Specifies the library to use instead of libphobos when linking. Options specifying the linkage of libphobos, such as-static-libphobosor-shared-libphobos, are ignored.-debuglib=libname: Specifies the debug library to use instead of libphobos when linking. This option has no effect unless the-goption was also given on the command line. Options specifying the linkage of libphobos, such as-static-libphobosor-shared-libphobos, are ignored.-nophoboslib: Doesn't use the Phobos or D runtime library when linking. Options specifying the linkage of libphobos, 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 both a shared and a static library, this forces 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 if your system ships both a shared and a static copy of libgphobos and libgdruntime, this flag forces the static version ๐ If the static one wasn't built when the compiler was configured, this flag does literally nothing ๐
โจ Developer Options โจ
This part is for the devs and language-tooling people ๐ค Lowkey not for everyday bestie-level usage, but iconic if you're in the weeds ๐ฅ
-fdump-d-originalโ dumps the internal front-end AST right after the"semantic3"stage ๐ This is only useful for debugging the GNU D compiler itself, so unless you're fixing gdc, skip it ๐-vโ the main character of debugging flags โจ It dumps info about the compiler's language processing stages while your source program is being compiled. That includes:- every module processed through the
"parse","semantic","semantic2", and"semantic3"stages - all
"import"modules and their file paths - all
"function"bodies being compiled
- every module processed through the
โจ SEE ALSO โจ
Check out gpl(7), gfdl(7), fsf-funding(7), and gcc(1), plus the Info entries for gdc and gcc ๐ง
โจ 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. There are 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).
That's the whole page, bestie! ๐ฆ Pulled from gcc-16, dated 2026-03-22, GDC(1) energy all the way ๐ Stay iconic ๐ โจ
๐ฆ where this page comes from
- ubuntu resolute: gdc-16-hppa-linux-gnu 16-20260322-1ubuntu1cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms