GDC(1)
okay so before we even get into it: this is gdc(1), the GNU manual's page for gdc β and yeah it's long, so hydrate π§ because we are going through EVERYTHING. no skimming, no skipping, that's the rule. let's go π
π NAME π
gdc β a GCC-based compiler for the D language. that's it, that's the whole vibe. it's the D-language compiler, and it's built on GCC, and it slays β¨
πΈ SYNOPSIS πΈ
okay so here's the shape of a basic invocation, bestie β look at it, it's giving options-on-options π
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
and real talk: that's only the most useful ones up there. the rest of them are allll the way down below, so keep scrolling, i promise it's worth it π₯
π¦ DESCRIPTION π¦
the gdc command is the GNU compiler for the D language, and here's the thing β it supports so many of the same options as gcc π«Ά that's the whole family resemblance. but this manual? this manual only documents the options that are specific to gdc. so if you're looking for some generic GCC flag, go read the gcc page, because this one isn't the one, bestie π
β¨ OPTIONS β¨
ποΈ Input and Output files
okay so plot twist: for any given input file, the file name suffix decides what kind of compilation happens. the compiler looks at the ending and goes "oh, i know what this is." here's the roster of supported input file name flavors π
file.dβ D source files. your classic.file.ddβ Ddoc source files.file.diβ D interface files.
you can absolutely drop more than one input file on the gdc command line, and each one gets compiled separately during the compilation process, no drama. BUT if you also pass an -o file option, then all the input files get compiled together into one single output file named file. and yes, that's allowed even when you're using -S or -c π«‘
now, a D interface file? it contains only what an import of the module actually needs, rather than the whole entire implementation of that module. little guy, minimal energy. you can make them with gdc from a D source file by using the -H option π and when the compiler goes to resolve an import declaration, it searches for matching .di files first, and only then for .d.
a Ddoc source file, meanwhile, contains code in the D macro processor language. it's primarily designed for producing user documentation from embedded comments, with a slight affinity towards HTML generation π and heads up: if a .d source file starts with the string "Ddoc", then it gets treated as general purpose documentation, not as a D source file. so, you know, be careful about naming a file like that π
β‘ Runtime Options
these options affect the runtime behavior of programs compiled with gdc. buckle up, there's a bunch π
-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.-fno-assertβ turn 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 to me: 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's the deal, that's the trade.-fbounds-check=valueβ an alternative to-fbounds-checkthat gives you more control over where bounds checking is turned on or off. here are the values it supports: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. gone. not a vibe check survived π
-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 one makes it stop doing that little trick.-fcheckaction=valueβ this option controls what code is generated on an assertion, bounds check, or final switch failure. the values it supports:contextβ throw anAssertErrorwith extra context information.haltβ halt the program execution. just. stop. πthrowβ throw anAssertErrorβ and this one is the default.
-fdebugβ turns on compilation of conditionaldebugcode into the program. the-fdebugoption by itself sets the debug level to1.-fdebug=valueβ turns on compilation of conditionaldebugcode into the program, and lets you enabledebugcode that's 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 supported values: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.
-fno-invariantsβ turns off code generation for classinvariantcontracts.-fmainβ generates a defaultmain()function when compiling. this is useful when unittesting a library, because it enables running the unittests in a library without having to manually define an entry-point function π«Ά heads up though: 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. the functions that are not be generated include module constructors and destructors (static thisandstatic ~this),unittestcode, andDSOregistry functions for dynamically linked code. that's a lot of things suddenly missing, so know what you're doing π-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. one gets the spotlight, the rest are just vibing in the background.-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. here are the values it supports:allβ turns on all upcoming D language features. the whole buffet π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. formerly incorrectly permitted!! that's a whole confession π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. no shared access, no exceptions, we respect the boundary π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 values it supports: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 here's the consequence, no sugarcoating: any code that uses features of the language that require access to this information will result in an error π-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. like, lights out.-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. pick your fighter π€Ί
π Options for Directory Search
these options specify directories to search for files, libraries, and other parts of the compiler. the "where do i look for stuff" category π
-Idirβ specify a 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 gave them.-Jdirβ specify a directory to use when searching for files in string imports at compile time. and real talk: this switch is required in order to useimport(file)expressions. multiple-Joptions can be used, and the paths are searched in the same order. no-J, no string imports, periodt π-Ldirβ when the compiler is linking, this says "hey, go look in dir for libraries too", exactly like it does forgcc. π-Bdirβ tells gdc where to find its own stuff: the executables, the libraries, the source files, the data files of the compiler itself. Same energy asgcc. Like, this is where the compiler's own snack drawer lives π-fmodule-file=module=specβ okay so this one is the β¨path remappingβ¨ option. If a module you import matches all of module, or at least the leftmost chunk of it, then the file path in spec is what gets used to find the D sources. You reach for this when your source file paths and names do not line up with the package/module hierarchy. Bestie, look at this:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
So that right there tells the compiler: when you're importing A.B, go search every import path for the source file foo.d, and when you're importing C, go search the directory bar/. And here's what that looks like from the D code's side:
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
See how A.B.C doesn't match, because that leftmost-part match is doing the work. iykyk π¦
-imultilib dirβ use dir as the subdirectory of the gcc directory that holds the target-specific D sources and interfaces.-iprefix prefixβ sets prefix as the prefix for the gcc directory that holds target-specific D sources and interfaces. If your prefix is a directory, please include the trailing/, no cap.-nostdincβ do not go poking around the standard system directories for D source and interface files. The only directories that get searched are the ones you gave with-Ioptions (plus the directory of the current file, if that applies). Like, you're locking the front door but leaving the side gate open πΈ
π₯ Code Generation π₯
Besides the metric ton of gcc options that control code generation, gdc has a bunch of its own. Let's go π
-Hβ generates D interface files for every module being compiled. The compiler figures out the output file name from the name of the input file: strip out any directory components, strip the suffix, then slap a.disuffix on it. Slay.-Hd dirβ identical to-H, except the interface files get written to the directory dir. You can pair it with-Hf fileso you can set the output file and the directory path independently of each other.-Hf fileβ same as-Hbut the interface files go to file. Pair it with-Hd dirif you want the output file and the directory path set independently.-Mβ spits out the module dependencies of every source file being compiled, in a formatmakecan actually eat. The compiler outputs one make rule containing the object file name for that source file, a colon, then the names of all the imported files. Makefile bestie behavior π«Ά-MMβ same as-Mbut it stays quiet about imported modules that come from the D standard library package directories.-MF fileβ when used with-Mor-MM, this says which file to write the dependencies to. And when used with the driver options-MDor-MMD,-MFoverrides the default dependency output file.-MGβ this one exists purely for compatibility withgcc, and the compiler just ignores it. It's giving decorative π-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 that dependency generation emits, to be exactly the string you type. Want multiple targets? Either pass them all as a single argument to-MT, or just use multiple-MToptions. Your call π-MQ targetβ same as-MT, but it quotes any characters that are special tomake.-MDβ this is equivalent to-M -MF file. The driver works outfileby removing any directory components and the suffix from the input file, then adding a.depssuffix.-MMDβ like-MD, but it does not mention imported modules from the D standard library package directories.-Xβ outputs info describing the contents of all the source files being compiled, in JSON format, to a file. The driver works outfileby removing any directory components and the suffix from the input file, then adding a.jsonsuffix.-Xf fileβ same as-X, but all the JSON contents get written to the specified file.-fdocβ generates "Ddoc" documentation and writes it to a file. The compiler works outfileby removing any directory components and the suffix from the input file, then adding a.htmlsuffix.-fdoc-dir=dirβ same as-fdoc, but the documentation gets written to directory dir. You can use it with-fdoc-file=fileto set the output file and the directory path independently.-fdoc-file=fileβ same as-fdoc, but the documentation gets written to file. Use it with-fdoc-dir=dirto set the output file and the directory path independently.-fdoc-inc=fileβ names file as a Ddoc macro file to be read. You can stack multiple-fdoc-incoptions, and the files get read and processed in the exact order you list them.-fdump-c++-spec=fileβ for D source files, generate 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. This is genuinely so useful for debugging compilation errors, and it gives debuggers source to show when they ask for it. ππ
π Warnings π
Warnings are diagnostic messages. They report constructions that aren't inherently erroneous but that are risky, or that suggest there's probably a bug lurking in your program. Unless you specify -Werror, they do not stop the program from compiling. Just saying, bestie.
-Wallβ turns on all warning messages. Warnings are not a defined part of the D language, and every construct that might produce one of these warnings is valid code. So likeβ¦ valid, but sus π-Wallocaβ warns on every single use of "alloca" in the source.-Walloca-larger-than=nβ warns on unbounded uses ofalloca, and on bounded uses ofallocawhose bound could be larger than n bytes. And-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 a signature that doesn't match.-Wcast-resultβ warns about casts that will produce a null or zero result. Right now this only happens for casting between an imaginary and a non-imaginary data type, or casting between a D and a C++ class.-Wno-deprecatedβ do not warn about usage of deprecated features and symbols that have "deprecated" attributes.-Werrorβ turns all warnings into errors. Everything is a problem now β¨-Wextraβ enables some extra warning flags that-Walldoes not turn on:
-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 though: this option does not report messages as warnings, so these messages never become errors even when the-Werroroption is also in play.-Wunknown-pragmasβ warns when apragma()shows up that gdc doesn't understand. Fun difference: with-fignore-unknown-pragmas, a pragma that is part of the D language but just not implemented by the compiler won't get reported. Different vibes entirely.-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 turns into an error. And ngl, 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, and once you hit that, gdc bails out instead of trying to keep processing the source code. If n is0(which is the default), there's no limit on how many error messages get produced. Chaos mode: default π-fsyntax-onlyβ checks the code for syntax errors but doesn't actually compile it. You can run this together with-fdocor-Hto generate files for each module present on the command-line, but no other output file.-ftransition=idβ reports extra info about D language changes identified by id. Here are 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 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. If the compiler is not doing a link step, they're meaningless. Like, they're just sitting there. Cute but useless π
-defaultlib=libnameβ specify the library to use instead oflibphoboswhen linking. Any options specifying the linkage oflibphobos, like-static-libphobosor-shared-libphobos, get ignored.-debuglib=libnameβ specify the debug library to use instead oflibphoboswhen linking. This option does nothing at all unless the-goption was also given on the command line. And yeah, options specifying the linkage oflibphobos, like-static-libphobosor-shared-libphobos, get ignored.-nophoboslibβ do not use the Phobos or D runtime library when linking. Options specifying the linkage oflibphobos, like-static-libphobosor-shared-libphobos, get 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 shared version to be used. If no shared version was built when the compiler was configured, this option has no effect. Zero. None. π«-static-libphobosβ on systems that providelibgphobosandlibgdruntimeas both a shared and a static library, this option forces the static version to be used. If no static version was built when the compiler was configured, this option has no effect.
π Developer Options π
This section describes command-line options that are primarily of interest to developers or language tooling. The niche girlies. The tooling girlies. We see you π
-fdump-d-originalβ drops the internal front-end AST after the"semantic3"stage. bestie this one is literally only for debugging the GNU D compiler itself, so unless you're out here fixing gdc, it's giving "not for you" π-vβ dumps all the tea about what the compiler's language-processing stages are doing while your source program compiles β¨ that means: it lists every module that gets processed through the"parse","semantic","semantic2", and"semantic3"stages; every"import"module and its file paths; and every"function"body that's being compiled. maximum transparency, no secrets, we love her for that π
π SEE ALSO π
okay so if you wanna go deeper (and you should, she's iconic), go read gpl(7), gfdl(7), fsf-funding(7), gcc(1), plus the Info entries for gdc and gcc ππ«Ά
π COPYRIGHT π
Copyright (c) 2006-2024 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 a wrap on the whole page, bestie π you just read the GDC(1) manual β that's source/version gcc-14.4.0, dated 2026-06-26 β go compile something cute, you ate that fr fr πβ¨
π¦ where this page comes from
- ubuntu stonking: gdc-14-sparc64-linux-gnu 14.4.0-2ubuntu1cross2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms