GDC(1)
๐ GDC(1) โ the GNU D compiler, bestie edition
okay so welcome to gdc, straight out of the GNU lineup ๐ this is a long one so grab a snack, we're going section by section and I'm not leaving anything out, iykyk.
๐ธ NAME ๐ธ
gdc โ a GCC-based compiler for the D language. that's it, that's the girl ๐
โจ SYNOPSIS โจ
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
ngl that list up there is literally just the greatest-hits version โ only the most useful options are listed here; see below for the remainder ๐ the rest of them are all down in OPTIONS and there are so many.
๐ซถ DESCRIPTION ๐ซถ
so gdc is the GNU compiler for the D language, and it supports a whole bunch of the same options as gcc ๐ but heads up โ this manual is only about the options that are specific to gdc, not the shared ones.
๐ OPTIONS ๐
๐ Input and Output files ๐
for any given input file, the suffix on the file name is what decides what kind of compilation happens. no cap, the suffix runs the show. here's what's supported:
file.dโ D source files. the main characters ๐file.ddโ Ddoc source files.file.diโ D interface files.
you can drop more than one input file on the gdc command line, and each one gets compiled separately during the compilation process. but if you pass a -o file option, then all the input files get compiled together, producing one single output file named file โจ and yes, that's allowed even when you're using -S or -c.
a D interface file only contains what an import of the module needs โ not the whole implementation of that module, bestie, just the vibes you need to import it. you can make them with 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 holds 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 twist: if a .d source file starts with the string "Ddoc" then it's treated as general purpose documentation, not as a D source file. plot twist fr fr ๐
๐ Runtime Options ๐
these options affect the runtime behavior of programs compiled with gdc. so like, the compiler's out of the picture and your program is living its life โ these are the settings that shape it.
-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 โ like from__traits(compiles, ...)โ or that come from an imported module that isn't being compiled. so if you want absolutely every single one, this is your girl.-fno-assertโ turns off code generation forassertcontracts. bye-bye asserts ๐-fno-bounds-checkโ turns off array bounds checking for all functions, which can improve performance for code that uses arrays extensively. but bestie, listen: this can result in unpredictable behavior if the code in question actually does violate array bounds constraints. it is safe to use if you're sure your code never throws aRangeError. be so for real before you flip this one.-fbounds-check=valueโ an alternative to-fbounds-checkthat gives you way more control over where bounds checking is turned on or off ๐๏ธ here's the supported values: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.-fcheckaction=valueโ this option controls what code gets generated on an assertion, bounds check, or final switch failure ๐ supported values:contextโ throw anAssertErrorwith extra context information.haltโ halt the program execution.throwโ throw anAssertError(the default).
-fdebug,-fdebug=valueโ turns on compilation of conditionaldebugcode into the program ๐ the-fdebugoption itself sets the debug level to 1, while-fdebug=enablesdebugcode that's identified by any of the following values:- ident โ turns on compilation of any
debugcode identified by ident.
- ident โ turns on compilation of any
-fno-druntimeโ implementshttps://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. supported values:c++98,c++03โ sets__traits(getTargetInfo, "cppStd")to 199711.c++11โ sets__traits(getTargetInfo, "cppStd")to 201103.c++14โ sets__traits(getTargetInfo, "cppStd")to 201402.c++17โ sets__traits(getTargetInfo, "cppStd")to 201703. this is the default.c++20โ sets__traits(getTargetInfo, "cppStd")to 202002.
-fno-invariantsโ turns off code generation for classinvariantcontracts.-fmainโ generates a defaultmain()function when compiling โจ this one is so useful when unittesting a library, because it lets you run the unittests in a library without having to manually define an entry-point function. it does nothing whenmainis already defined in user code, so no conflict, no drama.-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 ๐ฅ 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 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 ๐ฎ supported values: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. 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. supported values: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. and heads up bestie: any code that uses features of the language that require access to this information will result in an error. it's giving "you asked for it" ๐ญ-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 of
versioncode identified by ident.
- ident โ turns on compilation of
-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โ specify a directory to use when searching for imported modules at compile time. multiple-Ioptions can be used, and the paths are searched in the same order. order matters, bestie, it's a whole queue.-Jdirโ specify a 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 you're linking, this says โbestie, go look in dir for libraries too,โ exactly like gcc does it. ๐-Bdirโ tells the compiler where to find its own executables, libraries, source files, and data files, just like gcc. It's giving โI know where I liveโ energy. ๐-fmodule-file=module=specโ okay so this one is a whole vibe for imported modules. If an imported module matches all of module or the leftmost part of it, then the file path in spec becomes the spot to search for D sources. It's your โthese file paths and names are NOT matching the package and module hierarchyโ rescue. ๐
Consider this example:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
This tells the compiler: search all import paths for the source file foo.d when importing A.B, and search the directory bar/ when importing C, like the D code below shows:
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 has target-specific D sources and interfaces. ๐ธ-iprefix prefixโ set prefix as the prefix for the gcc directory containing target-specific D sources and interfaces. If the prefix is a directory, bestie, include that final/. Slash included, periodt. ๐-nostdincโ do NOT search the standard system directories for D source and interface files. Only the directories you gave with-Ioptions (plus the current file's directory, if that's appropriate) get searched. ๐ซ
๐ Code Generation ๐
On top of the many gcc options that control code generation, gdc has its own little collection. And yes, they're iconic. โจ
-Hโ generates D interface files for all modules being compiled. The compiler picks the output file based on the input file's name, strips any directory components and suffix, then slaps on.di. ๐-Hd dirโ same as-H, but writes those interface files into directory dir. You can use this with-Hf fileto independently set the output file and directory path. ๐-Hf fileโ same as-Hbut writes interface files to file. Can be used 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 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 doesn't mention imported modules from the D standard library package directories. Lowkey the same, highkey less noisy. ๐-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 is for compatibility with gcc, and is ignored by the compiler. It's literally just there to vibe. ๐-MPโ outputs a phony target for each dependency other than the modules being compiled, causing each to depend on nothing. Iconic make trick. โจ-MT targetโ change the target of the rule emitted by dependency generation to be exactly the string you specify. 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. She's careful. ๐-MDโ equivalent to-M -MF file. The driver determines file by 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. Standard library stays out of it. ๐ซ-Xโ outputs information 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, and then adding a.jsonsuffix. JSON bestie! ๐-Xf fileโ same as-X, but writes all 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, and then adding a.htmlsuffix. Docs slay. ๐-fdoc-dir=dirโ same as-fdoc, but writes documentation to directory dir. 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 to file. This option can be used with-fdoc-dir=dirto independently set the output file and directory path. ๐-fdoc-inc=fileโ specify 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. Order matters, bestie. ๐-fdump-c++-spec=fileโ for D source files, generate 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. Extra chatty. ๐ฌ-fsave-mixins=fileโ generates code expanded from D"mixin"statements and writes the processed sources to file. This is useful to debug errors in compilation and provides source for debuggers to show when requested. Debugging glow-up. ๐
๐ 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. So like, they're the group chat going โbestie are you sure?โ but they won't stop the show. ๐ญ
-Wallโ turns on all warning 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. She's loud but valid. ๐ข-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-Walloca-larger-thanwarning and is equivalent to-Walloca-larger-than=SIZE_MAXor larger. Math is mathing. ๐งฎ-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. Currently this is only done for casting between an imaginary and non-imaginary data type, or casting between a D and C++ class. She's checking your casts. ๐-Wno-deprecatedโ do not warn about usage of deprecated features and symbols with"deprecated"attributes. Living in the past? Not her problem. ๐-Werrorโ turns all warnings into errors. No more warning era, only error era. ๐-Wextraโ enables some extra warning flags that are not enabled by-Wall. The extra ones are:-Waddress,-Wcast-result,-Wmismatched-special-enum,-Wunknown-pragmas. More warnings, more power. โจ-Wmismatched-special-enumโ warns when an enum the compiler recognizes as special is declared with a different size to the built-in type it is representing. Size mismatch = warning. ๐-Wspeculativeโ lists 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. Speculative tea. โ-Wunknown-pragmasโ warns when apragma()is encountered that is not understood by gdc. 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 like"va_start". Questionable usage? Not today. ๐-fignore-unknown-pragmasโ turns off errors for unsupported pragmas. Let them be. ๐-fmax-errors=nโ limits the maximum number of error messages to n, at which point gdc bails out rather than attempting to continue processing the source code. If n is0(the default), there is no limit on the number of error messages produced. Set your limit, bestie. ๐-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. Vibe check only. ๐-ftransition=idโ reports additional information about D language changes identified by id. The supported values are: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 bad boys only matter when the compiler is linking object files into an executable output file. If there's no link step, they're literally meaningless. Periodt. ๐
-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โ 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. ๐ฟ
๐ Developer Options ๐
This section is for the devs and language tooling girlies. Options that are mostly interesting if you're building the compiler or working on tooling. โจ
-fdump-d-originalโ output the internal front-end AST after the"semantic3"stage. This option is only useful for debugging the GNU D compiler itself. ๐ง-vโ bestie, this one is the behind-the-scenes cam ๐ฅ and it is so nosy in the best way. It dumps info about the compiler's language processing stages while your source program is being compiled. What's in the dump? Listen:- every module that gets processed through the
"parse","semantic","semantic2", and"semantic3"stages ๐ - all
"import"modules plus their file paths (so you can see exactly where it's pulling stuff from, no cap) - and all
"function"bodies that are being compiled
- every module that gets processed through the
Likeโฆ it's giving "compiler diary, unlocked" ๐โจ. If you've ever been squinting at a build going "okay but WHAT is it even doing rn", this is your answer fr fr.
๐ SEE ALSO ๐
Go read your sisters, bestie, they're all iconic in their own lanes ๐
โฆand also the Info entries for gdc and gcc, which are lowkey the main characters if you want the deep lore ๐ซถ
๐ COPYRIGHT ๐
Copyright (c) 2006-2023 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). ๐โจ
Translation bestie: yes you can copy/distribute/modify this doc, go off, just follow the license terms above and grab the full text from gfdl(7). Periodt. ๐
And that's the whole page, bestie!! ๐ธ This one shipped as version gcc-13.5.0 and it's dated 2026-09-10 โ that's the source and the date right there, the little footer origin story ๐ฆโจ Thanks for reading all three parts, you ate that ๐๐
๐ฆ where this page comes from
- ubuntu stonking: gdc-13-sparc64-linux-gnu 13.5.0-1ubuntu1cross1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms