GDC(1)
π GDC(1) β welcome to the group chat
okay so first things first: this is GDC(1), the GNU manual page for gdc, and bestie, we're gonna get through the WHOLE thing together. grab a snack π
β¨ NAME
gdc β a GCC-based compiler for the D language. that's it, that's the whole vibe check. π
π¦ SYNOPSIS
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
okay so only the most useful options are listed here β the rest are down below, so keep scrolling, we're not done. π
πΈ DESCRIPTION
gdc is the GNU compiler for the D language, and the way it slays is that it supports many of the same options as gcc. iconic family resemblance honestly. π«Ά
but heads up: this manual only documents the options that are specific to gdc β like, the special ones. the gcc-isms live in their own house. π
π OPTIONS
π Input and Output files
okay so for any given input file, the file name suffix is what tells the compiler what kind of compilation to do. it's giving "your extension is your personality." 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 gets compiled separately in the compilation process. cute, right? π
now: if you specify a -o file option, then all the input files are compiled together, producing a single output file named file. and yes, this is allowed even when you're using -S or -c. slay.
A D interface file contains only what an import of the module needs, rather than the whole entire implementation of that module. very minimal, very main-character-restraint. β¨ 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.
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. and here's the fun bit π¦ β if a .d source file starts with the string "Ddoc" then it is treated as general purpose documentation, not as a D source file. plot twist.
π§ Runtime Options
these options affect the runtime behavior of programs compiled with gdc. like, what your binary does after it leaves the house. π
-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.-fno-assertβ Turn off code generation for"assert"contracts. no thoughts, no asserts. π-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 a"RangeError". π-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 the"core.stdc"package is a built-in function.-fcheckaction=valueβ This option controls what code is generated on an assertion, bounds check, orfinal switchfailure. The following values are supported:contextβ Throw an"AssertError"with extra context information.haltβ Halt the program execution.throwβ Throw an"AssertError"(the default).
-fdebug,-fdebug=valueβ Turn on compilation of conditional"debug"code into the program. The-fdebugoption itself sets the debug level to1, while-fdebug=enables"debug"code that are identified by any of the following values:identβ Turns on compilation of any"debug"code 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 of libphobos.-fno-invariantsβ Turns off code generation for class"invariant"contracts.-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 when"main"is already defined in user code. π§-fno-moduleinfoβ Turns off generation of the"ModuleInfo"and 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 this"and"static ~this"),"unittest"code, and"DSO"registry 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. (so it reads everything, but only writes one thing. picky. love that. π )-fno-postconditionsβ Turns off code generation for postcondition"out"contracts.-fno-preconditionsβ Turns off code generation for precondition"in"contracts.-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 for"alias this"before searching in upper scopes.fiximmutableconvβ Disallows unsound immutable conversions that were formerly incorrectly permitted.inβ Implements"in"parameters to mean"scope const [ref]"and accepts rvalues.inclusiveincontractsβ Implements"in"contracts 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 to"ref"parameters.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β 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 like, don't, unless you know. π-fno-switch-errorsβ This option controls what code is generated when no case is matched in a"final switch"statement. The default run time behavior is to throw a"SwitchError". Turning off-fswitch-errorsmeans that instead the execution of the program is immediately halted. (dramatic much? yes. correct? also yes. π₯)-funittestβ Turns on compilation of"unittest"code, and turns on theversion(unittest)identifier. This implies-fassert.-fversion=valueβ Turns on compilation of conditional"version"code into the program identified by any of the following values:identβ Turns on compilation of"version"code 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:
and that's exactly where part one leaves us, bestie β mid-sentence, right on the directory-search cliffhanger. π no cap, the next part picks it right up, so don't go anywhere. π
-Idirβ tells the compiler "bestie, go look in dir when you're hunting down imported modules at compile time." You can stack multiple-Ioptions and the paths get searched in the exact same order you gave them, no queue-jumping π-Jdirβ same idea but for files pulled in by string imports at compile time. This switch is literally required if you wanna useimport(file)expressions. Multiple-Joptions? Totally fine, and again the paths are searched in the order you listed them β¨-Ldirβ when linking, this says "here's a library search directory," exactly likegccdoes it.-Bdirβ points the compiler at where its own executables, libraries, source files, and data files live, just like thegccversion of this flag.-fmodule-file=module=specβ this one's a lil path-remix tool π If an imported module matches all of module, or at least its leftmost chunk, then the file path in spec becomes the place to search for D sources. Basically it's for when your source file paths/names don't line up with the package and module hierarchy. Peep this:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
So that tells the compiler: search all the import paths for the source file foo.d when importing A.B, and look in the directory bar/ when importing C. Like so, as annotated in this 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β use dir as a subdirectory of the gcc directory that holds target-specific D sources and interfaces.-iprefix prefixβ sets prefix as the prefix for the gcc directory containing target-specific D sources and interfaces. If that prefix is a directory, do yourself a favor and include the final/π«Ά-nostdincβ do not go searching the standard system directories for D source and interface files. Only the directories you specified with-Ioptions (plus the directory of the current file, if that's appropriate) get searched. Periodt.
β¨ Code Generation β¨
On top of the many gcc options that control code generation, gdc has a bunch of options that are all its own. Main character energy π
-Hβ generates D interface files for every module being compiled. The compiler figures out the output file from the name of the input file: strips any directory components and the suffix, then slaps a.disuffix on there.-Hd dirβ same as-H, but writes the interface files into directory dir. You can pair this with-Hf fileso you can set the output file and the directory path independently π-Hf fileβ same as-Hbut writes interface files to file. Works alongside-Hd dirto set the output file and directory path independently.-Mβ outputs the module dependencies of all source files being compiled, in a format thatmakecan actually eat. The compiler spits out one make rule containing the object file name for that source file, a colon, and the names of all imported files.-MMβ like-Mbut it does not mention imported modules from the D standard library package directories. Keeping it lowkey π€«-MF fileβ when used with-Mor-MM, this specifies a file to write the dependencies to. When used with the driver options-MDor-MMD,-MFoverrides the default dependency output file.-MGβ this one exists purely for compatibility with gcc, and the compiler just ignores it. It's giving "invited but not actually participating" π-MPβ outputs a phony target for each dependency other than the modules being compiled, which makes each one depend on nothing.-MT targetβ changes the target of the rule emitted by dependency generation to be exactly the string you specify. Want multiple targets? Pass them as a single argument to-MT, or just use multiple-MToptions. Your call, bestie.-MQ targetβ same as-MT, but it quotes any characters that are special tomake. Safety first β¨-MDβ equivalent to-M -MF file. The driver works out file by stripping 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 info describing the contents of all source files being compiled, in JSON format, to a file. The driver determines file by removing 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 out. The compiler determines file by stripping any directory components and suffix from the input file, then adding an.htmlsuffix.-fdoc-dir=dirβ same as-fdoc, but writes documentation into directory dir. You can use this with-fdoc-file=fileto set the output file and directory path independently π-fdoc-file=fileβ same as-fdoc, but writes documentation to file. Can be combined with-fdoc-dir=dirto set the output file and directory path independently.-fdoc-inc=fileβ specifies file as a Ddoc macro file to be read. Multiple-fdoc-incoptions are allowed, and the files are read and processed in the order you gave them.-fdump-c++-spec=fileβ for D source files, generates the corresponding C++ declarations into file.-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 the code expanded from D"mixin"statements and writes the processed sources to file. Super useful for debugging compilation errors, and it gives debuggers some source to show when they ask for it π
πΈ Warnings πΈ
Warnings are diagnostic messages reporting constructions that aren't inherently erroneous but are risky, or that suggest there's probably a bug lurking in your program. Unless -Werror is specified, they do not stop the program from compiling. So they're like, a vibe check, not a blocker π
-Wallβ turns on all warning messages. Warnings are not a defined part of the D language, and every construct that might trigger one is still valid code. So don't panic.-Wallocaβ warns on all uses of"alloca"in the source.-Walloca-larger-than=nβ warns on unbounded uses ofalloca, and on bounded uses ofallocawhose bound can be larger than n bytes.-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 gets declared with an incompatible signature. Rude, honestly.-Wcast-resultβ warns about casts that will produce a null or zero result. Currently it only does this 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 that carry"deprecated"attributes.-Werrorβ turns every single warning into an error. No warnings survive, they all get promoted π€-Wextraβ enables some extra warning flags that-Walldoesn't turn on:-Waddress-Wcast-result-Wmismatched-special-enum-Wunknown-pragmas
-Wmismatched-special-enumβ warns when an enum the compiler recognizes as special gets 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 though: this option does not report messages as warnings, and those messages therefore never become errors, even when-Werroris also used π«Ά-Wunknown-pragmasβ warns when apragma()comes up thatgdcdoesn't understand. This differs from-fignore-unknown-pragmas, where a pragma that's part of the D language but not implemented by the compiler won't get reported.-Wno-varargsβ do not warn on questionable usage of the macros used to handle variable arguments, like"va_start".-fno-ignore-unknown-pragmasβ do not recognize unsupported pragmas. Anypragma()encountered that isn't part of the D language results in an error. > Fair warning bestie: this option is now deprecated and will be removed in a future release π-fmax-errors=nβ caps the maximum number of error messages at 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 doesn't actually compile it. Can be used with-fdocor-Hto generate files for each module on the command-line, but no other output file. It's giving "just here to observe" π-ftransition=idβ reports extra info about D language changes identified by id. 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 show up when the compiler links object files into an executable output file. If the compiler isn't doing a link step, they're literally meaningless. Situational icons only β¨
-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. This option has no effect unless the-goption was also given on the command line. Options specifying the linkage oflibphobos, like-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. Going fully independent, love that for you π«Ά-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. Can't force what doesn't exist π-static-libphobosβ bestie, on systems that providelibgphobosandlibgdruntimeas a shared and a static library, this option forces the use of the static version. If no static version was built when the compiler was configured, this option has no effect. Thatβs it, thatβs the rule π
π οΈ Developer Options π οΈ
Okay so this section is for the devs and language-tooling girlies β these command-line options are primarily of interest to developers or language tooling. Slay for the toolchain, honestly.
-fdump-d-originalβ outputs the internal front-end AST after thesemantic3stage. This option is only useful for debugging the GNU D compiler itself, so itβs giving very much βcompiler dev main character energyβ πβ¨-vβ dumps information about the compiler language processing stages as the source program is being compiled. This includes listing all modules that are processed through theparse,semantic,semantic2, andsemantic3stages; allimportmodules and their file paths; and allfunctionbodies that are being compiled. Literally the whole backstage tour, no cap π¬π
π SEE ALSO π
Go check out gpl(7), gfdl(7), fsf-funding(7), gcc(1), and the Info entries for gdc and gcc. Link-up complete, bestie π«Ά
π 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). Legally iconic, fr fr π
π Thatβs the tea: this page is source/version gcc-16, dated 2026-10-29. Stay iconic, bestie β mwah! π
β¨πΈ
π¦ where this page comes from
- fedora 44: gcc-gdc 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms