GDC(1)
π GDC(1) β the GNU D compiler, bestie edition π
okay so you found the manual for gdc, the GNU compiler for the D language, and honestly? it's a lot. but don't panic, we're gonna walk through it together, one flag at a time, no cap. πΈ
β¨ NAME β¨
gdc β a GCC-based compiler for the D language. that's it, that's the whole vibe. π
β¨ SYNOPSIS β¨
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
lowkey important: only the most useful options are listed up there β the rest of them live down below, and we will be going through all of them, bestie. no skipping. π«Ά
β¨ DESCRIPTION β¨
The gdc command is the GNU compiler for the D language, and it supports so many of the same options as gcc. This manual? 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 π
For any given input file, the file name suffix decides what kind of compilation is happening. it's giving "your extension is your destiny". β¨
The following kinds of input file names are supported:
file.dβ D source files. the classic. the main character. πfile.ddβ Ddoc source files.file.diβ D interface files.
You can specify more than one input file on the gdc command line, and each one gets compiled separately in the compilation process. If you specify a -o file option, though, all the input files get compiled together, producing a single output file named file. and yes, this is allowed even when you're using -S or -c. iconic behaviour honestly. π
A D interface file contains only what an import of the module needs β not 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. so .di is the VIP line, .d is general admission. π
A Ddoc source file contains 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 heads up: 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. π
π₯ Runtime Options π₯
These options affect the runtime behavior of programs compiled with gdc. so like, not how it builds β how it acts when it's out there living its life.
-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 not being compiled. so this flag is the "actually, do all of it" button. πͺ-fno-assertβ Turn off code generation forassertcontracts. no asserts, no problem (until there's a problem).-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're sure that your code never throws aRangeError. 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. just. stop. π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:- level β Sets the debug level to level, any
debugcode<= levelis compiled into the program. - ident β Turns on compilation of any
debugcode identified by ident.
- level β Sets the debug level to level, any
-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, because 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. (it knows when to sit down. π«Ά)-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. so everybody gets checked, but only one gets the code. main character energy. π-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. everything, all at once. π₯dip1000β Implements <https://wiki.dlang.org/DIP1000> (Scoped pointers).dip1008β Implements <https://wiki.dlang.org/DIP1008> (Allow exceptions in@nogccode).dip1021β Implements <https://wiki.dlang.org/DIP1021> (Mutable function arguments).dip25β Implements <https://wiki.dlang.org/DIP25> (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, fast but 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=β 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://wiki.dlang.org/DIP25> (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. Any code that uses features of the language that require access to this information will result in an error. so, like, choose wisely. π-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. abrupt. π-funittestβ Turns on compilation ofunittestcode, and turns on theversion(unittest)identifier. This implies-fassert. testing era. π§-fversion=valueβ Turns on compilation of conditionalversioncode into the program identified by any of the following values:- level β Sets the version level to level, any
versioncode>= levelis compiled into the program. - ident β Turns on compilation of
versioncode identified by ident.
- level β Sets the version level to level, any
-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. it's giving "where do I even look for things" energy. π
-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. so order matters, bestie. π-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. no-J, no string imports, fr fr. π«Ά-Ldirβ When linking, specify a library search directory, as withgcc.-Bdirβ This option specifies where to find the executables, libraries, source files, and data files of the compiler itself, as withgcc. it's the compiler's own little home address. π β¨
and that's where part 1 wraps, but we are so not done β more of this manual is coming, so stay tuned, don't go anywhere. π
-fmodule-file=module=specβ okay bestie, this one is a lil β¨fancyβ¨. It messes with the file paths of your imported modules, so if an imported module matches all of module or just the leftmost chunk of it, then the file path in spec gets used as the place to go hunting for D sources. You reach for this when your source file paths and names are not the same as your package and module hierarchy. Peep these examples:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
So this tells the compiler: when you import A.B, go search all the import paths for the source file foo.d; and when you import C, go search the directory bar/. Like, as annotated in this D code right here:
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
-imultilibdir β use dir as a subdirectory of the gcc directory that holds target-specific D sources and interfaces.-iprefixprefix β set prefix as the prefix for the gcc directory containing target-specific D sources and interfaces. Heads up: if the prefix is itself a directory, you gotta include that final/. π«Ά-nostdincβ do not go looking through 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 β¨
So besides all the gajillion gcc options that control code generation, gdc has a bunch of its very own. main character options, honestly. π
-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.-Hddir β same as-H, but it writes those interface files into directory dir. You can pair this with-Hffile so you set the output file and the directory path independently.-Hffile β same as-Hbut writes the interface files to file. Works together with-Hddir to set the output file and directory path independently.-Mβ outputs the module dependencies of all source files being compiled, in a format thatmakecan actually eat. The compiler spits out one make rule containing the object file name for that source file, a colon, and then the names of all the imported files.-MMβ like-M, except it does not mention imported modules from the D standard library package directories.-MFfile β when used with-Mor-MM, this says which file to write the dependencies to. And when you use it with the driver options-MDor-MMD,-MFoverrides the default dependency output file.-MGβ this one exists purely for compatibility with gcc, and the compiler justβ¦ ignores it. π-MPβ outputs a phony target for each dependency other than the modules being compiled, which makes each of them depend on nothing.-MTtarget β 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. π-MQtarget β same as-MT, except it quotes any characters that are special tomake.-MDβ this is equivalent to-M -MFfile. The driver works out file by stripping any directory components and the suffix off 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 works out file by stripping any directory components and the suffix off the input file, then adding a.jsonsuffix.-Xffile β 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 works out file by stripping any directory components and the suffix off the input file, then adding an.htmlsuffix.-fdoc-dir=dir β same as-fdoc, but writes the docs into directory dir. Pair it with-fdoc-file=file to set the output file and directory path independently.-fdoc-file=file β same as-fdoc, but writes the docs to file. Pair it with-fdoc-dir=dir to 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 exact same order you gave them. πΈ-fdump-c++-spec=file β for D source files, generates the corresponding C++ declarations into file.-fdump-c++-spec-verboseβ used alongside the-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 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 reporting constructions that aren't inherently erroneous, but are risky or suggest there's probably a bug lurking in your program. Unless -Werror is specified, they do not stop your program from compiling. no cap.
-Wallβ turns on all warning messages. Real talk: warnings are not a defined part of the D language, and every construct that might trigger one here is still valid code.-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.-Wcast-resultβ warns about casts that'll produce a null or zero result. Currently 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β do not warn about usage of deprecated features and symbols that have"deprecated"attributes.-Werrorβ turns every warning into an error. scary, but iconic. π-Wspeculativeβ lists all error messages from speculative compiles, like"__traits(compiles, ...)". Important: this option does not report messages as warnings, so these messages never become errors even when the-Werroroption is also in play.-Wtemplatesβ warns whenever a template instantiation is encountered. Some coding rules straight up disallow templates, so this is your enforcer.-Wunknown-pragmasβ warns when a"pragma()"shows up thatgdcdoesn't understand. This is different from-fignore-unknown-pragmas, where 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".-fignore-unknown-pragmasβ turns off errors for unsupported pragmas.-fmax-errors=n β caps the max number of error messages at n, at which 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 does not actually compile it. You can use this with-fdocor-Hto generate files for each module present on the command-line, but it produces no other output file.-ftransition=id β reports extra information 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.vmarkdownβ list instances of Markdown replacements in Ddoc.
π Options for Linking π
These options kick in when the compiler links object files into an executable output file. If the compiler isn't doing a link step, they're literally meaningless. π¦
-defaultlib=libname β specify the library to use instead oflibphoboswhen linking. Options that specify the linkage oflibphobos, like-static-libphobosor-shared-libphobos, get 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, 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 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. 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 static version. If no static version was built when the compiler was configured, this option has no effect.
π οΈ Developer Options π οΈ
This section is all about command-line options that are mainly of interest to developers or language tooling. iykyk.
-fdump-d-originalβ outputs the internal front-end AST after the"semantic3"stage. This option is only useful for debugging the GNU D compiler itself.-vβ dumps info about the compiler language processing stages while the source program is being compiled. That includes listing all modules processed through the"parse","semantic","semantic2", and"semantic3"stages; all"import"modules and their file paths; and all"function"bodies that are being compiled. π
π SEE ALSO π
gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entries for gdc and gcc.
β¨ COPYRIGHT β¨
Okay bestie, legal era π but make it cute:
- Copyright (c) 2006-2022 Free Software Foundation, Inc.
And now the permission part, which is literally the most generous glow-up ever: 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
- no Back-Cover Texts
A copy of the license is included in the man page gfdl(7). Go read it, it's giving β¨ required reading β¨ no cap π
And that's the whole page, bestie!! π This one came from gcc-12 and it's dated 2022-03-19, and yeah it lives under the name GDC(1) ππ
Mwah π go compile something iconic, you absolute legend ππΈ
π¦ where this page comes from
- ubuntu jammy: gdc-12 12-20220319-1ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms