GDC(1)
π GDC(1) π
okay bestie, welcome to gdc from the GNU girlies β this is the manual page for the compiler, and we're gonna go through it together, no skimming, no skipping, every single flag accounted for. π
β¨ NAME β¨
gdc β a GCC-based compiler for the D language. literally that's the whole vibe. π¦
β¨ SYNOPSIS β¨
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
no cap, this is only the most useful options β the rest are hanging out further down, so keep scrolling bestie π.
β¨ DESCRIPTION β¨
The gdc command is the GNU compiler for the D language, and she supports so many of the same options as gcc β like, the family resemblance is real. But heads up: this manual only documents the options that are specific to gdc. So if you're looking for the generic GCC stuff, wrong page, go find gcc(1). π«Ά
β¨ OPTIONS β¨
πΈ Input and Output files πΈ
okay so for any given input file, the suffix of the file name decides what kind of compilation happens. like a vibe check by extension, iykyk. here's what's supported:
file.dβ D source files. the classic. πfile.ddβ Ddoc source files.file.diβ D interface files.
You can absolutely put more than one input file on the gdc command line, bestie β each one gets compiled separately during the compilation process. and if you hand her a -o file option, then all the input files get compiled together, producing one single output file, named file. 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 β not the whole entire implementation of that module, just the essentials. she's giving minimalist queen. You can create 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 contains code in the D macro processor language. It is primarily designed for use in producing user documentation from embedded comments, with a slight affinity towards HTML generation. and here's the tea: 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. so like, not how your code compiles β how it lives its life once it's running. π
-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 forassertcontracts. gone. deleted. π-fno-bounds-checkβ Turns off array bounds checking for all functions, which can improve performance for code that uses arrays extensively.
β οΈ bestie listen to me: 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. are you sure? like sure sure? π«£
-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 thecore.stdcpackage is a built-in function.-fcheckaction=valueβ This option controls what code is generated on an assertion, bounds check, or final switch failure. The following values are supported:contextβ Throw anAssertErrorwith extra context information.haltβ Halt the program execution.throwβ Throw anAssertError(the default).
-fdebug,-fdebug=valueβ Turn on compilation of conditionaldebugcode into the program. The-fdebugoption itself sets the debug level to 1, while-fdebug=enablesdebugcode that are 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>. 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 oflibphobos.-fno-invariantsβ Turns off code generation for classinvariantcontracts. bye girl π-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 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 be 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. selective queen. π-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.
β οΈ say it with me: undefined behavior. not a vibe. be careful out there. π
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β 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. test girlies rise π«Ά-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:
(and that's where part 1 leaves us bestie β hold that thought, more is coming π)
-Idirβ okay bestie, this is your import-path plug π you hand it a dir to search when it's hunting down imported modules at compile time. Stack up as many-Ioptions as you like, and the paths get searched in exactly the order you listed them.-Jdirβ same energy, different job πΈ say what dir to search for files that show up in string imports at compile time. This switch is required if you wanna useimport(file)expressions, no way around it. Multiple-Joptions? yes ma'am, and the paths are searched in the same order.-Ldirβ when it's linking, this names a library search directory, literally as withgcc.-Bdirβ this one tells the compiler where to find its own executables, libraries, source files, and data files, as withgcc. It's pointing at the compiler's own stuff, not yours π-fmodule-file=module=specβ this one messes with the file paths of imported modules π§ if an imported module matches all of module or the leftmost chunk of it, then the file path in spec is what gets used as the place to search for D sources. You want this when the source file paths and names don't line up with the package and module hierarchy. Check the examples:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
So that's telling the compiler: when importing A.B, search all the import paths for the source file foo.d; when importing C, search the directory bar/. Like the D code below annotates:
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 thegccdirectory where the target-specific D sources and interfaces live.-iprefix prefixβ set prefix as the prefix for thegccdirectory that holds the target-specific D sources and interfaces. Heads up π«Ά if the prefix is 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 named with-Ioptions get searched (plus the directory of the current file, if that applies).
β¨ Code Generation β¨
On top of the many gcc options that control code generation, gdc has several options that are its own thing entirely π
-Hβ generates D interface files for every module being compiled. The compiler figures out the output file from the name of the input file: it strips any directory components and the suffix, then slaps a.disuffix on it.-Hd dirβ same as-H, but the interface files get written to directory dir. You can pair this with-Hf fileso you set the output file and the directory path independently.-Hf fileβ same as-Hbut writes the interface files to file. Pair it with-Hd dirto set the output file and the directory path independently, together.-Mβ spits out the module dependencies of all the source files being compiled, in a format thatmakecan eat. The compiler outputs one make rule holding the object file name for that source file, a colon, and the names of all the imported files.-MMβ like-Mbut it does not mention imported modules from the D standard library package directories.-MF fileβ when you use it with-Mor-MM, it names a file to write the dependencies to. When you use it with the driver options-MDor-MMD,-MFoverrides the default dependency output file.-MGβ this exists for compatibility withgcc, and the compiler straight up ignores it π-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. Either works π-MQ targetβ same as-MT, except it quotes any characters that are special tomake.-MDβ equivalent to-M -MF file. The driver works out file by removing any directory components and the 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 gets file by removing any directory components and suffix from the input file and 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 a.htmlsuffix.-fdoc-dir=dirβ same as-fdoc, but writes the documentation to directory dir. Works alongside-fdoc-file=fileso you can set the output file and directory path independently.-fdoc-file=fileβ same as-fdoc, but writes documentation to file. Works alongside-fdoc-dir=dirto set the output file and directory path independently.-fdoc-inc=fileβ names file as a Ddoc macro file to be read. Multiple-fdoc-incoptions are allowed, and the files get read and processed in the same order.-fdump-c++-spec=fileβ for D source files, generates the corresponding C++ declarations in file.-fdump-c++-spec-verboseβ used with-fdump-c++-spec=above, it adds 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. This one is genuinely useful for debugging compilation errors, and it gives debuggers source to show when they're asked π
π©· Warnings π©·
Warnings are diagnostic messages that report constructions that aren't inherently erroneous but are risky or suggest there's probably a bug in the program. Unless -Werror is specified, they do not stop the program from compiling.
-Wallβ turns on all warning messages. Warnings are not a defined part of the D language, and every construct that this might generate a warning for is valid code.-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 is declared with an incompatible signature.-Wcast-resultβ warns about casts that will produce a null or zero result. Right now 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 with "deprecated" attributes.-Werrorβ turns all warnings into errors π-Wextraβ enables some extra warning flags that-Walldoesn't enable:
-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, like__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()shows up thatgdcdoesn't understand. This differs from-fignore-unknown-pragmas: with that one, 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. Heads up though: 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 at that 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. You can use this with-fdocor-Hto generate files for each module present on the command line, with no other output file.-ftransition=idβ reports extra info 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 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, just so you know β¨
-defaultlib=libnameβ names the library to use instead oflibphoboswhen linking. Options that specify the linkage oflibphobos, like-static-libphobosor-shared-libphobos, get ignored.-debuglib=libnameβ names the debug library to use instead oflibphoboswhen linking. This one has no effect unless-gwas 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 do get 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 does nothing at all π«-static-libphobosβ okay so some systems out here ship libgphobos and libgdruntime in both a shared flavor and a static one πΈ and this flag is you saying "static please, bestie." β¨ But real talk: if the compiler was configured without a static version ever being built in the first place? This option literally does nothing. It has no effect. Zero. Nada. π
π οΈ Developer Options π οΈ
This bit is for the devs and the language-tooling girlies β options that are primarily of interest to developers or language tooling. π§ You probably don't need these unless you're literally working on the compiler itself, iykyk.
-fdump-d-originalβ dumps out the internal front-end AST after the"semantic3"stage π«Ά This one is only useful for debugging the GNU D compiler itself β like, it's for the compiler's own glow-up, not yours. π-vβ shows you all the compiler language processing stages while your source program is getting compiled π₯ This includes listing:- every module that gets processed through the
"parse","semantic","semantic2", and"semantic3"stages - all
"import"modules and their file paths - and all
"function"bodies that are being compiled
- every module that gets processed through the
It's giving full transparency, no secrets, we're all main characters here π
π SEE ALSO π
Go read these next, bestie, they're part of the lore:
β¦plus the Info entries for gdc and gcc π
Β©οΈ 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). Slay. β¨
fr fr that's the whole page π go compile something iconic π
And that's a wrap on GDC(1), babes π«Ά this was v gcc-15.3.0, dated 2026-06-12. Go forth and D your little heart out ππ
β¨
π¦ where this page comes from
- ubuntu stonking: gdc-15-powerpc-linux-gnu 15.3.0-4ubuntu1cross1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms