GDC(1)
GDC(1) โ the GNU D compiler, but make it a group chat ๐
okay bestie, welcome to gdc from the GNU fam โ this is the manual page for it, and yes it is A Whole Thing, so buckle up ๐ซถ
โจ 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...
ngl, that's literally just the most useful options up there โ the rest are further down, keep scrolling bestie ๐
โจ DESCRIPTION โจ
The gdc command is the GNU compiler for the D language, and it supports a lot of the same options as gcc. No cap.
But heads up: this manual page? It only documents the options that are specific to gdc. So if you're looking for the generic GCC stuff, that's a different page, iykyk. ๐
โจ OPTIONS โจ
๐ Input and Output files
So for any input file you throw at it, the file name suffix is what decides what kind of compilation happens. The vibes are determined entirely by the ending, basically. Here's what's supported:
file.dโ D source files. The classic. ๐file.ddโ Ddoc source files.file.diโ D interface files.
You can pass more than one input file on the gdc command line, and each one gets compiled separately in the compilation process. Periodt. But if you specify 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 โ the compiler said slay, we ball. ๐
A D interface file contains only what an import of the module needs, not the whole implementation of that module. Very demure, very minimal. 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, and then for .d. Order matters bestie, don't forget it.
A Ddoc source file 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 plot 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. The compiler said "not today, D source." ๐
๐ฆ Runtime Options
These options affect the runtime behavior of programs compiled with gdc. So like, not the compiling itself โ the actual running of the thing. Very main character energy. โจ
-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 this flag is the "no, do literally all of them" button. ๐ฅ-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's safe to use this option if you're sure your code never throws aRangeError. If you're not sure? Don't. ๐- *
-fbounds-check=value* โ An alternative to-fbounds-checkthat lets you have more control over where bounds checking gets 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. This flag is like "I don't know her." ๐ซถ- *
-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. Just. Stop. Immediately. ๐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=value enablesdebugcode that's identified by any of the following values:levelโ Sets the debug level to level; anydebugcode<=level is compiled into the program.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. the class said "I'm fine actually" ๐-fmainโ Generates a defaultmain()function when compiling. This is useful when unittesting a library, because it lets you run the unittests in a library without having to manually define an entry-point function. And this option does nothing whenmainis already defined in user code. If you already wrote it, she's not gonna double up on you. ๐-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 generated include module constructors and destructors (static thisandstatic ~this),unittestcode, andDSOregistry functions for dynamically linked code. Big "I'm going minimal" energy. โจ- *
-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. Look at everything, write down one thing. ๐ -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.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.inโ Implementsinparameters to meanscope const [ref]and accepts rvalues.inclusiveincontractsโ Implementsincontracts of overridden methods to be a superset of parent contract.intpromoteโ Implements C-style integral promotion for unary+,-and~expressions.nosharedaccessโ Turns off and disallows all access to shared memory objects.rvaluerefparamโ Implements rvalue arguments torefparameters.shortenedmethodsโ Implements use of=>for methods and top-level functions in addition to lambdas.
-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. So like, she's fast but she's feral. ๐ญ
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=id* โ Turns off a D language feature identified by id. The following values are supported:allโ Turns off all revertable D language features.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.markdownโ Turns off Markdown replacements in Ddoc comments.
-fno-rttiโ Turns off generation of run-time type information for all user defined types. And heads up: any code that uses features of the language that require access to this information will result in an error. So it's not "quietly missing," it's "loudly refusing." ๐-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. No throwing, no catching, just. gone. ๐ซ-funittestโ Turns on compilation ofunittestcode, and turns on theversion(unittest)identifier. This implies-fassert. test szn bestie ๐ง- *
-fversion=value* โ Turns on compilation of conditionalversioncode into the program identified by any of the following values:levelโ Sets the version level to level; anyversioncode>=level is compiled into the program.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. Very "let me look around" of them. ๐
- *
-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 you gave them. First one wins, so put your faves first bestie ๐ -Jdirโ tells the compiler where to go look for files when it hits a string import at compile time ๐ซถ. This switch is required if you wanna useimport(file)expressions, no way around it. You can stack multiple-Joptions too, and the paths get searched in the exact order you wrote them in. Bestie behavior.-Ldirโ when linking, this says "hey, look for libraries in here," same energy asgcc. ๐-Bdirโ points at where to find the executables, libraries, source files, and data files of the compiler itself, again just likegcc. ๐ธ-fmodule-file=module=specโ this one is lowkey iconic: it messes with the file paths of imported modules, so if an imported module matches all of module or just the leftmost part of it, then the file path in spec is what gets used as the location to search for D sources. Use this when your source file paths and names don't line up with your package and module hierarchy. Look at these examples:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
This tells the compiler to search in all import paths for the source file foo.d when importing A.B, and the directory bar/ when importing C, exactly 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 not forget the final/. ๐-nostdincโ do not search the standard system directories for D source and interface files. Only the directories you specified with-Ioptions get searched (plus the directory of the current file, if that's appropriate). ๐
๐ Code Generation ๐
Besides the many gcc options controlling code generation, gdc has a bunch of options that are its own special thing. Not like other girls, fr fr.
-Hโ generates D interface files for all modules 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.dion there. ๐ฆ-Hd dirโ same as-H, but it writes the interface files into directory dir. You can pair this with-Hf fileto set the output file and the directory path independently. ๐-Hf fileโ same as-Hbut writes the interface files to file. Works with-Hd dirso you can set the output file and directory path independently. โจ-Mโ spits out the module dependencies of every source file being compiled in a format that's suitable formake. The compiler outputs one make rule containing the object file name for that source file, a colon, and the names of all the imported files. Periodt.-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 the file to write the dependencies to. When you use it with the driver options-MDor-MMD,-MFoverrides the default dependency output file. ๐-MGโ this one exists purely for compatibility withgcc, and the compiler ignores it. It's giving "invited to the party but not actually doing anything." ๐-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. Wanna have multiple targets? You can either pass them all as a single argument to-MT, or just use multiple-MToptions. Main character choices only. ๐-MQ targetโ same as-MT, except it quotes any characters that are special tomake. ๐-MDโ this option is equivalent to-M -MF file. The driver figures out file by removing any directory components and the suffix from the input file, then adding a.depssuffix. ๐-MMDโ like-MDbut it 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 figures out file by removing any directory components and the suffix from the input file, then adding a.jsonsuffix. โจ-Xf fileโ same as-X, but it writes all that JSON content to the file you specify. ๐-fdocโ generatesDdocdocumentation and writes it to a file. The compiler figures out file by removing any directory components and the suffix from the input file, then adding a.htmlsuffix. ๐ธ-fdoc-dir=dirโ same as-fdoc, but it writes the documentation into directory dir. Pair it with-fdoc-file=fileto set the output file and directory path independently. ๐-fdoc-file=fileโ same as-fdoc, but it writes the documentation to file. Pair it 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 use multiple-fdoc-incoptions, and the files get read and processed in the same order. ๐-fdump-c++-spec=fileโ for D source files, this generates the corresponding C++ declarations into file. ๐ฅ-fdump-c++-spec-verboseโ used together with-fdump-c++-spec=above, it adds comments for ignored declarations in the generated C++ header. ๐ซถ-fsave-mixins=fileโ generates code expanded from Dmixinstatements and writes the processed sources to file. Super useful for debugging errors in compilation, and it gives debuggers source to show when they ask for it. ๐
๐ญ Warnings ๐ญ
Warnings are diagnostic messages reporting constructions that aren't inherently erroneous but that are risky, or that suggest there's probably a bug lurking in the program. Unless -Werror is specified, they do not stop the program from compiling. So they're like, the gentle bestie concerned-voice, not the blocking one. ๐ฅบ
-Wallโ turns on all warning messages. Warning: warnings are not a defined part of the D language, and every construct that might generate a warning message is still valid code. So like, valid but sus. ๐-Wallocaโ warns on every single use ofallocain 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. ๐-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 that havedeprecatedattributes. ๐-Werrorโ turns all warnings into errors. Every warning is now a hard stop, no chill. ๐-Wspeculativeโ lists all error messages from speculative compiles, like__traits(compiles, ...). Heads up: this option does not report messages as warnings, and so those messages never become errors even when the-Werroroption is also used. ๐-Wtemplatesโ warns whenever a template instantiation is encountered. Some coding rules disallow templates, and this is how you enforce that rule. ๐-Wunknown-pragmasโ warns when apragma()shows up thatgdcdoesn't understand. Note that this differs from-fignore-unknown-pragmas, where a pragma that is part of the D language but just isn't implemented by the compiler won't get reported. ๐ซถ-Wno-varargsโ do not warn on questionable usage of the macros used to handle variable arguments likeva_start. ๐-fignore-unknown-pragmasโ turns off errors for unsupported pragmas. โจ-fmax-errors=nโ limits the max number of error messages to n, at which pointgdcbails out instead of trying to keep processing the source code. If n is0(the default), there's no limit on the number of error messages produced. ๐-fsyntax-onlyโ checks the code for syntax errors but doesn't actually compile it. You can use this alongside-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. 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 ofinon parameter. ๐nogcโ list all hidden GC allocations. ๐จtemplatesโ list statistics on template instantiations. ๐tlsโ list all variables going into thread local storage. ๐งตvmarkdownโ list instances of Markdown replacements in Ddoc. ๐
๐ฅ 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, so don't come for them if nothing happens. ๐
-defaultlib=libnameโ specifies the library to use instead oflibphoboswhen linking. Any options specifying 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, 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 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 both 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 describes command-line options that are primarily of interest to developers or language tooling. Niche but iconic. ๐ซถ
-fdump-d-originalโ outputs the internal front-end AST after thesemantic3stage. This option is only useful for debugging the GNU D compiler itself. ๐ง-vโ bestie, this flag dumps ALL the tea โ about the compiler's language processing stages while your source program is being compiled ๐โจ. It lists every module that gets processed through theparse,semantic,semantic2, andsemantic3stages, all theimportmodules and their file paths, and everyfunctionbody that's being compiled. It's literally the compiler's diary entries, no cap ๐ .
๐ธ SEE ALSO ๐ธ
gpl(7)๐gfdl(7)๐fsf-funding(7)๐ซถgcc(1)๐- and the Info entries for
gdcandgcc๐ฆ
๐ COPYRIGHT ๐
okay so legal tea, don't skip this bestie:
Copyright (c) 2006-2022 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).
this page is from gcc-12.5.0, dated 2025-07-11, and it's GDC(1) โ slay ๐
โจ
๐ฆ where this page comes from
- ubuntu questing: gdc-12-sparc64-linux-gnu 12.5.0-6ubuntu1cross1
- ubuntu resolute: gdc-12-sparc64-linux-gnu 12.5.0-9ubuntu1cross1
- ubuntu stonking: gdc-12-sparc64-linux-gnu 12.5.0-9ubuntu1cross1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms