GDC(1)
πΈ GDC(1) β GNU πΈ
okay bestie, welcome to the GDC manual page β that's gdc from the GNU fam, section 1 of the manual set. grab a snack, this one's a ride π
β¨ NAME β¨
gdc β a GCC-based compiler for the D language π¦
β¨ SYNOPSIS β¨
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
fr fr only the most useful options are listed up there β the rest of them are living further down this page, see below π
β¨ DESCRIPTION β¨
So gdc is the GNU compiler for the D language, and it's lowkey built different β it supports a whole bunch of the same options as gcc does. But heads up: this manual page only documents the options that are specific to gdc. everything else? that's a gcc thing, iykyk π
β¨ OPTIONS β¨
π Input and Output files π
okay so for any given input file, the file name suffix is what decides what kind of compilation gets done. here's the whole lineup of supported input file names π
file.dβ D source files πfile.ddβ Ddoc source files πfile.diβ D interface files π
You can absolutely specify more than one input file on the gdc command line β each one gets compiled separately in the compilation process. and if you pass a -o file option, then all the input files are 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, rather than the whole implementation of that module. 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 is primarily designed for use in producing user documentation from embedded comments, with a slight affinity towards HTML generation. If a .d source file starts with the string Ddoc then it is treated as general purpose documentation, not as a D source file. π¦
πΈ Runtime Options πΈ
These options affect the runtime behavior of programs compiled with gdc. periodt π«Ά
-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. π-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 aRangeError. π-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 to1, 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++98c++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, 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. π-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 @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 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. 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. π§-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 in COMDAT or 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. π-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 the compiler is linking, this tells it to also look in dir for libraries, exactly like the same flag ingcc. π-Bdirβ this one tells the compiler where to find its own stuff: the executables, libraries, source files and data files that make up the compiler itself. Same deal as withgcc. β¨-fmodule-file=module=specβ okay so this is the module-path-rewriter, and it's lowkey iconic. It messes with the file paths of imported modules so that if an imported module matches all of module, or just the leftmost chunk of it, then the path in spec becomes the place to go hunting for D sources. You reach for this when your source file paths and names don't line up with the package/module hierarchy. Peep these examples:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
That tells the compiler: whenever anything imports A.B, search every import path for the source file foo.d; and whenever anything imports C, search the directory bar/. Here's the D code it's annotating, bestie:
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, the one holding target-specific D sources and interfaces. π-iprefix prefixβ sets prefix as the prefix of that gcc directory containing the target-specific D sources and interfaces. If your prefix is a directory, include the final/, okay? Don't forget it. π-nostdincβ nope, no standard system directories for D source and interface files. Only the directories you explicitly handed over with-Ioptions (plus the directory of the current file, if that applies) get searched. Bye standard paths π
π» Code Generation π»
So besides the metric ton of gcc options that control code generation, gdc has a few of its very own. Main character options only. β¨
-Hβ generates D interface files for every module being compiled. The compiler figures out the output filename from the name of the input file: strip any directory components and the suffix, then slap.dion the end. π«Ά-Hd dirβ same as-Hbut drops the interface files into directory dir. You can pair it with-Hf fileto set the output file and the directory path independently. πΈ-Hf fileβ same as-Hbut writes interface files to file. Pair with-Hd dirwhen you want to set the output file and the directory path independently. π¦-Mβ outputs the module dependencies of all the source files being compiled, formatted somakecan actually use it. The compiler spits out one make rule: the object file name for that source file, a colon, and then the names of all the imported files. Chef's kiss for build systems. π₯-MMβ like-M, but it stays quiet about imported modules that come from the D standard library package directories.-MF fileβ when you're using-Mor-MM, this picks file as the place to write the dependencies to. And when it's used with the driver options-MDor-MMD,-MFoverrides the default dependency output file. π-MGβ purely there for compatibility withgcc. The compiler ignores it. It's just vibing. π-MPβ outputs a phony target for each dependency other than the modules being compiled, so each one depends on nothing. Peak "I need no one" energy.-MT targetβ changes the target of the rule emitted by dependency generation to be exactly the string you give it. Want multiple targets? Either pass them all as a single argument to-MT, or just use-MTmultiple times. π-MQ targetβ same as-MT, except it quotes any characters that are special tomake. Protect those special little characters π«Ά-MDβ equivalent to-M -MF file. The driver works out file by stripping any directory components and the suffix from the input file, then adding a.depssuffix.-MMDβ like-MD, but it doesn't 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 out file by stripping any directory components and the suffix from the input file, then adding a.jsonsuffix. JSON girlies rise π-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 determines file by removing any directory components and suffix from the input file, then adding an.htmlsuffix. Docs era β¨-fdoc-dir=dirβ same as-fdoc, but writes the documentation into directory dir. Can be used together with-fdoc-file=fileto set the output file and directory path independently.-fdoc-file=fileβ same as-fdoc, but writes the documentation to file. Can be used together with-fdoc-dir=dirto set the output file and 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 same order you gave them. Order matters, bestie. π-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. Receipts for everything π-fsave-mixins=fileβ generates code expanded from D"mixin"statements and writes the processed sources to file. Genuinely useful for debugging compilation errors, and it gives debuggers actual source to show when they ask for it. So helpful it's giving main character energy π
β οΈ Warnings β οΈ
Okay so warnings are these diagnostic messages that report constructions which aren't inherently erroneous but are risky, or which suggest there's probably a bug lurking in the program. Unless you specify -Werror, they do not stop the program from compiling. They're just the compiler going "bestieβ¦ are you sure?" π
-Wallβ turns on all warning messages. Important vibe check: warnings are not a defined part of the D language, and every construct that might trigger one is valid code. So nothing here is "illegal", it's just sus. π-Wallocaβ warns on every single use of"alloca"in the source.-Walloca-larger-than=nβ warns on unbounded uses ofalloca, and also on bounded uses ofallocawhose bound could be bigger than n bytes. And-Wno-alloca-larger-thandisables the-Walloca-larger-thanwarning β it's equivalent to-Walloca-larger-than=SIZE_MAXor larger. π-Wno-builtin-declaration-mismatchβ warns if a built-in function gets declared with an incompatible signature. Not the vibe.-Wcast-resultβ warns about casts that will produce a null or zero result. Right now this only fires for casting between an imaginary and a non-imaginary data type, or casting between a D and a C++ class. π-Wno-deprecatedβ don't warn about usage of deprecated features and symbols that have"deprecated"attributes. Let them live their truth.-Werrorβ turns all warnings into errors. Everything is serious now. No more "just a warning" excuses π-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 that the compiler recognises as special is declared with a different size than the built-in type it's representing. Mismatch detected, red flag π©-Wspeculativeβ lists all error messages from speculative compiles, like"__traits(compiles, ...)". Heads up though: this option does not report those messages as warnings, which means they never turn into errors even when-Werroris also in play. Important distinction, don't get it twisted π«Ά-Wunknown-pragmasβ warns when apragma()shows up thatgdcdoesn't understand. Note the difference from-fignore-unknown-pragmas: here, a pragma that's part of the D language but simply not implemented by the compiler won't get reported. β¨-Wno-varargsβ don't warn on questionable usage of the macros used to handle variable arguments, like"va_start". π-fignore-unknown-pragmasβ turns off errors for unsupported pragmas. Ignorance is bliss, officially supported.-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(which is the default), there's no limit at all on how many error messages get produced. Brace yourself. π-fsyntax-onlyβ checks the code for syntax errors but doesn't actually compile it. Fabulous combo with-fdocor-Hto generate files for each module on the command line, while producing no other output file. Just vibes and validation π-ftransition=idβ reports extra info about D language changes identified by id. These 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 ones only matter when the compiler is actually linking object files into an executable output file. If there's no link step happening, they're meaningless. Literally zero thoughts, head empty. π¦
-defaultlib=libnameβ picks the library to use instead oflibphoboswhen linking. Any options that specify the linkage oflibphobos, like-static-libphobosor-shared-libphobos, get ignored. Sorry not sorry π-debuglib=libnameβ picks the debug library to use instead oflibphoboswhen linking. It has no effect unless the-goption was also given on the command line. And again, options specifying the linkage oflibphobos, like-static-libphobosor-shared-libphobos, are ignored. π-nophoboslibβ don't 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 still get used like normal, unless-nostdlibor-nodefaultlibsis used. DIY era β¨-shared-libphobosβ on systems that shiplibgphobosandlibgdruntimeas both a shared and a static library, this forces the shared version. If no shared version was built when the compiler was configured, this option has no effect. π-static-libphobosβ on systems that shiplibgphobosandlibgdruntimeas both a shared and a static library, this forces the static version. If no static version was built when the compiler was configured, this option has no effect. Snug and self-contained π«Ά
π οΈ Developer Options π οΈ
This section is for the options that are mainly of interest to developers or to language tooling. Nerds only, respectfully. π
-fdump-d-originalβ outputs the internal front-end AST after the"semantic3"stage. This one is only useful for debugging the GNU D compiler itself. You're not gonna need it unless you're in the compiler, iykyk π§-vβ bestie this one is a whole vibe check on your compiler π it dumps info about the language processing stages while your source program is getting compiled. What's in the dump, you ask? everything: every module that goes through the"parse","semantic","semantic2", and"semantic3"stages, all the"import"modules plus their file paths, and all the"function"bodies that are being compiled. it's giving backstage pass energy fr fr π
β¨ SEE ALSO β¨
okay so if you wanna go deeper (and you know you do π¦), go check out:
gpl(7)gfdl(7)fsf-funding(7)gcc(1)- and the Info entries for
gdcandgccπ
π COPYRIGHT π
Copyright (c) 2006-2023 Free Software Foundation, Inc.
so here's the legal tea, and it's actually kind of iconic πΈ β 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 the whole page, bestie ππ you made it to the end!! literally so proud of you. this one's from gcc-13, dated 2026-09-10, and it lives at GDC(1) β go compile something beautiful with it β¨π§π
π¦ where this page comes from
- opensuse-leap 16.0: gcc13-d 13.5.0+git10516-160000.1.1 Β· GPL-3.0-or-later
- opensuse-leap 16.0: gcc13-d 13.5.0+git10516-160000.1.1 Β· GPL-3.0-or-later
- opensuse-leap 16.0: gcc13-d 13.5.0+git10516-160000.1.1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms