GDC(1)
πΈ NAME πΈ
gdc β a GCC-based compiler for the D language. that's the whole name bestie, short and slay π
β¨ SYNOPSIS β¨
okay so here's the vibe of how you actually call it:
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
real talk: only the most useful options are listed up there, so keep reading below for the rest of them. don't come for me, the list is long π
π DESCRIPTION π
so the gdc command is the GNU compiler for the D language, and it supports a ton of the same options as gcc β like, they're cousins, they share a wardrobe π«Ά
this manual only documents the options that are specific to gdc though, so don't expect the whole gcc saga in here. iykyk.
π OPTIONS π
π Input and Output files π
for any input file you hand over, the file name suffix decides what kind of compilation happens. it's giving "your extension is your destiny". the following kinds of input file names are supported:
file.dβ D source files. 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. but!! if you specify a -o file option, then all the input files are compiled together, producing a single output file, named file. and yes, this is allowed even when you're using -S or -c. no cap. π₯
a D interface file contains only what an import of the module needs, rather than the whole implementation of that module. you can make 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 only then for .d. so .di is literally first in line, as it should be π
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 here's the little plot twist: if a .d source file starts with the string Ddoc, then it gets treated as general purpose documentation, and not as a D source file. sneaky β¨
π¦ Runtime Options π¦
these options affect the runtime behavior of programs compiled with gdc. so like, they change what your program does when it's actually 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 that isn't being compiled. so this flag is basically "no, do everything, i said what i said" π-fno-assertβ turn off code generation forassertcontracts. gone. bye.-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: 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. and only then. fr fr.-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. so this is you telling the compiler "i know her, but no". π-fcheckaction=valueβ this option controls what code is generated on an assertion, bounds check, orfinal switchfailure. the following values are supported:contextβ throw anAssertErrorwith extra context information. the gossip included πhaltβ halt the program execution. abrupt. iconic.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++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. she's the moment π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 lets you run the unittests in a library without having to manually define an entry-point function. π«Ά this option does nothing whenmainis already defined in user code β like, if you already brought your own, she's not gonna fight you on it.-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 everyone gets read, but only one gets the spotlight β¨-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. the everything bagel π₯―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. nobody touches the shared memory, periodt.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. so, like, she will simply refuse π-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. lights off, party over.-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.
π Options for Directory Search π
these options specify directories to search for files, libraries, and other parts of the compiler. it's basically telling gdc where to go look for things π§
-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. first come, first searched π-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. so if you're wondering why your string imports are throwing a fit β it's because you forgot this one. every single time π
<div style="display:none">okay that's the first chunk, and there's way more coming β don't go anywhere bestie π</div>
β¦and that's where part 1 wraps, but hold on, we are not done β more of this page is coming, so keep scrolling π«Άβ¨
-Ldirβ when you're linking, this tells the compiler where to go looking for libraries, exactly like it does withgcc. Your girl does not make up new rules for the classics. π-Bdirβ this one points the compiler at where it can find its own executables, libraries, source files and data files. Again, same energy asgcc. β¨-fmodule-file=module=specβ okay this one is giving β¨file path manipulationβ¨ and it's lowkey iconic. If an imported module matches all of, or the leftmost part of, module, then the file path in spec is used as the place to search for D sources. Bestie, you want this when your source file paths and names do NOT line up with the package and module hierarchy. Look at these examples:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
So this tells the compiler: search in all import paths for the source file foo.d when importing A.B, and search in the directory bar/ when importing C β just like it says in this little annotated D snippet:
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β set prefix as the prefix for the gcc directory containing target-specific D sources and interfaces. Heads up: if that prefix represents a directory, you gotta include the final/. Don't forget it, babe. π-nostdincβ do NOT search the standard system directories for D source and interface files. The only places searched are the directories you specified with-Ioptions (plus the directory of the current file, if appropriate). We're keeping it tight. π₯
β¨ Code Generation β¨
On top of the many gcc options that control code generation, gdc has a few of its own. Not me being obsessed with a compiler having personal touches, but here we are. π
-Hβ generates D interface files for every module being compiled. The compiler figures out the output file from the input file's name: it strips any directory components and the suffix, then slaps on the.disuffix. π-Hd dirβ same as-H, but writes those interface files to directory dir. You can use this with-Hf fileto set the output file and the directory path independently. Mix and match, bestie. β¨-Hf fileβ same as-Hbut it writes interface files to file. Works with-Hd dirso you can set the output file and directory path independently. π-Mβ outputs the module dependencies of all source files being compiled, in a format thatmakecan vibe with. 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. Chef's kiss. π-MMβ like-M, but it does NOT mention imported modules from the D standard library package directories. Filtered, filtered. π§-MF fileβ when used with-Mor-MM, this specifies a file to write the dependencies to. And when it's used with the driver options-MDor-MMD,-MFoverrides the default dependency output file. Slay. πΈ-MGβ this one exists for compatibility withgcc, and the compiler straight up ignores it. It's just there to keep the peace. π-MPβ outputs a phony target for each dependency other than the modules being compiled, which makes each of them depend on nothing. Iconic phony behavior. β¨-MT targetβ changes the target of the rule emitted by dependency generation to be exactly the string you specify. Want multiple targets? You can pass them as a single argument to-MT, or just use multiple-MToptions. Your call, main character. π-MQ targetβ same as-MT, except it quotes any characters that are special tomake. Safety first. π«Ά-MDβ this is equivalent to-M -MF file. The driver determines file by removing any directory components and 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 determines file by removing any directory components and suffix from the input file, then adding a.jsonsuffix. JSON girlies rise up. π₯-Xf fileβ same as-X, but it 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 an.htmlsuffix. Documentation? We love her. π-fdoc-dir=dirβ same as-fdoc, but it writes the documentation to directory dir. Use it with-fdoc-file=fileto independently set the output file and directory path. π-fdoc-file=fileβ same as-fdoc, but it writes the documentation to file. Pairs with-fdoc-dir=dirfor independent output file + directory path energy. β¨-fdoc-inc=fileβ specifies 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. πΈ-fdump-c++-spec=fileβ for D source files, this generates corresponding C++ declarations into file. Interop moment. π₯-fdump-c++-spec-verboseβ used together with-fdump-c++-spec=above, it adds comments for ignored declarations in the generated C++ header. Verbose but make it cute. π-fsave-mixins=fileβ generates code expanded from D "mixin" statements and writes the processed sources to file. This is super useful for debugging compilation errors, and it gives debuggers source to show when they get asked. π«Ά
π Warnings π
Warnings are diagnostic messages that report constructions that are not inherently erroneous, but that are risky, or that suggest there's probably a bug in the program. Unless -Werror is specified, they do NOT stop the program from compiling. So likeβ¦ a heads-up, not a block. π
-Wallβ turns on all warning messages. And no, warnings are not a defined part of the D language, so every construct that this might warn about is still valid code. Periodt. π-Wallocaβ warns on all uses of "alloca" in the source. π-Walloca-larger-than=nβ warns on unbounded uses of alloca, and on bounded uses of alloca whose bound can be larger than n bytes. Also:-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. Mismatch? Not on our watch. π-Wcast-resultβ warns about casts that will produce a null or zero result. Currently 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 have"deprecated"attributes. Living in the past is a choice, bestie. π-Werrorβ turns all warnings into errors. All of them. Every last one. Good luck. π-Wextraβ enables some extra warning flags that aren't enabled by-Wall. The lineup is:-Waddress-Wcast-result-Wmismatched-special-enum-Wunknown-pragmas
-Wmismatched-special-enumβ warns when an enum that the compiler recognizes as special is declared with a different size than the built-in type it's representing. Sizing matters. π-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-Werroris also used. Sneaky but fair. β¨-Wunknown-pragmasβ warns when apragma()is encountered thatgdcdoesn't understand. Heads up, this differs from-fignore-unknown-pragmas, where a pragma that is part of the D language but isn't implemented by the compiler won't get reported. Different vibes, different reporting. π¦-Wno-varargsβ do not warn upon 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 will result in an error.
β οΈ Okay so real talk: this option is now deprecated and will be removed in a future release. Don't build your whole personality around it. π
-fmax-errors=nβ limits the maximum number of error messages to n, at which pointgdcbails out instead of trying to keep processing the source code. If n is0(which is the default), there's no limit on the number of error messages produced. πΈ-fsyntax-onlyβ checks the code for syntax errors, but does not 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. Just vibes, no binary. π₯-ftransition=idβ reports additional 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 options show up when the compiler links object files into an executable output file. If the compiler isn't doing a link step, they're literally meaningless. Zero effect. Nada. π
-defaultlib=libnameβ specifies the library to use instead oflibphoboswhen linking. And options that specify the linkage oflibphobos, like-static-libphobosor-shared-libphobos, get ignored. Sorry bestie, they're out. π«Ά-debuglib=libnameβ specifies the debug library to use instead oflibphoboswhen linking. This one 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β 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 get 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 to language tooling. Iykyk. π
-fdump-d-originalβ drops the internal front-end AST after thesemantic3stage, right into your lap. This one is only useful for debugging the GNU D compiler itself β like, it's for the compiler devs peeking under the hood, not for us mere mortals writing actual code π-vβ the yapper option π£οΈ It dumps everything about the compiler language processing stages while your source program is getting compiled. What's in the dump, bestie? Literally:- every module processed through the
parse,semantic,semantic2, andsemantic3stages - every
importmodule plus its file path - every
functionbody currently being compiled
- every module processed through the
So yeah, it's giving "tell me everything," and the compiler WILL tell you everything. Obsessed.
π SEE ALSO π
Go read these too, bestie, they're the whole friend group:
β¦and the Info entries for gdc and gcc, obviously. iykyk β¨
π 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). π«Ά
okay that's the whole page, you made it to the end π This icon was brought to you by gcc-14, dated 2024-09-08, and it's officially known as GDC(1). go compile something iconic, bestie πβ¨π¦
π¦ where this page comes from
- ubuntu noble: gdc-14-mips64el-linux-gnuabi64 14.2.0-4ubuntu2~24.04cross1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms