GDC(1)
๐ GDC(1) ยท the GNU manual ๐
โจ NAME โจ
gdc is a GCC-based compiler for the D language. It's giving main character energy ๐
โจ SYNOPSIS โจ
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
Okay so this is only the most useful options ๐ซถ The rest are down in the OPTIONS section, so keep reading, bestie.
โจ DESCRIPTION โจ
The gdc command is the GNU compiler for the D language, and it supports a lot of the same options as gcc ๐ธ This manual only covers the options that are specific to gdc, so you're not reading the same stuff twice.
โจ OPTIONS โจ
๐ฆ Input and Output files
For any input file, the file name suffix decides what kind of compilation happens. These are the input file name kinds that are supported:
file.dโ D source files ๐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 during the compilation process. If you use the -o file option, though, all the input files get compiled together into a single output file, named file. This still works with -S or -c ๐
A D interface file has only what an import of the module needs, not the whole implementation of that module. gdc can make these from a D source file with the -H option ๐ง When the compiler resolves an import declaration, it looks for matching .di files first, and only then for .d files.
A Ddoc source file has code in the D macro processor language. It's mainly built for making user docs out of embedded comments, with a little extra love for HTML generation ๐ If a .d source file starts with the string "Ddoc", then it gets treated as general purpose documentation instead of as a D source file. Not a D source file, bestie ๐
๐ฅ Runtime Options
These options change how programs compiled with gdc behave at runtime โญ
-fall-instantiationsโ Generates code for all template instantiations. By default, the template emission strategy is to skip generating code for declarations that were either instantiated speculatively (like from"__traits(compiles, ...)"), or that come from an imported module that isn't being compiled ๐-fno-assertโ Turns off code generation forassertcontracts ๐ซ-fno-bounds-checkโ Turns off array bounds checking for all functions. This can boost performance for code that uses arrays a lot ๐ฅ Heads up though, this can cause unpredictable behavior if the code actually does break array bounds constraints. It's only safe if you're sure your code never throws a"RangeError"๐-fbounds-check=valueโ An alternative to-fbounds-checkthat gives you more control over where bounds checking gets turned on or off. These 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โ Doesn't recognize built-in functions unless they start with the prefix__builtin_. By default, the compiler will recognize when a function in the"core.stdc"package is a built-in function ๐ง-fdebug,-fdebug=valueโ Turns on compilation of conditional"debug"code into your program. The-fdebugoption by itself sets the debug level to1, while-fdebug=turns on"debug"code that's identified by any of these values:levelโ Sets the debug level tolevel, and any"debug"code<= levelgets compiled into the program.identโ Turns on compilation of any"debug"code identified byident.
-fno-druntimeโ Implements the BetterC spec at<https://dlang.org/spec/betterc.html>. It assumes you're compiling for an environment with no D runtime library, so no runtime library, no cap ๐ฆ
This is the same as compiling with these options:
gdc -nophoboslib -fno-exceptions -fno-moduleinfo -fno-rtti
-fno-invariantsโ Turns off code generation for class"invariant"contracts ๐-fno-moduleinfoโ Turns off generation of the"ModuleInfo"stuff and related functions that would become unreferenced without it. This might let you link to programs that weren't written in D ๐ The functions that don't get generated include module constructors and destructors ("static this"and"static ~this"),"unittest"code, and"DSO"registry 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 byfilename๐-fno-postconditionsโ Turns off code generation for postcondition"out"contracts ๐ โโ๏ธ-fno-preconditionsโ Turns off code generation for precondition"in"contracts ๐ โโ๏ธ-freleaseโ Turns on release mode, which means no runtime checks for contracts and asserts get emitted. Array bounds checking isn't done for@systemand@trustedfunctions, and assertion failures are undefined behavior, so be careful, bestie ๐ญ
This is the same as compiling with these options:
gdc -fno-assert -fbounds-check=safe -fno-invariants \
-fno-postconditions -fno-preconditions -fno-switch-errors
-fno-rttiโ Turns off generation of run-time type information for all user defined types. Any code that uses language features needing this info will throw an error ๐ซ-fno-switch-errorsโ This option controls what code gets generated when no case matches in a"final switch"statement. The default runtime behavior is to throw a"SwitchError". Turning off-fswitch-errorsmeans that the program's execution is immediately halted instead ๐-funittestโ Turns on compilation of"unittest"code, and turns on theversion(unittest)identifier. This implies-fassert๐งช-fversion=valueโ Turns on compilation of conditional"version"code into the program, identified by any of these values:levelโ Sets the version level tolevel, and any"version"code>= levelgets compiled into the program.identโ Turns on compilation of"version"code identified byident.
-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 doesn't support weak symbols. Disabling this means common symbols get put in COMDAT or become private instead ๐ธ
๐บ๏ธ Options for Directory Search
These options tell the compiler which directories to search for files, libraries, and other parts of the compiler ๐งญ
-Idirโ Specifies a directory to search when looking for imported modules at compile time. You can use multiple-Ioptions, and the paths get searched in the same order ๐-Jdirโ Specifies a directory to search when looking for files in string imports at compile time. You need this switch to useimport(file)expressions. You can use multiple-Joptions, and the paths get searched in the same order ๐-Ldirโ When linking, specifies a library search directory, just like withgcc๐-Bdirโ Specifies where to find the executables, libraries, source files, and data files of the compiler itself, just like withgcc๐-fmodule-file=module=specโ This option messes with file paths of imported modules. If an imported module matches all or the leftmost part ofmodule, then the file path inspecgets used as the place to search for D sources. This is handy when the source file paths and names don't match the package and module hierarchy. Check out these examples:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
This tells the compiler to search all import paths for the source file foo.d when importing A.B, and the directory bar/ when importing C, as annotated in the D code below:
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โ Usesdiras a subdirectory of thegccdirectory that holds the target-specific D sources and interfaces ๐งฉ-iprefix prefixโ Specifiesprefixas the prefix for thegccdirectory that holds the target-specific D sources and interfaces. If the prefix represents a directory, you should include the final'/'๐-nostdincโ Doesn't search the standard system directories for D source and interface files. Only the directories you specified with-Ioptions (and the directory of the current file, if that applies) get searched ๐ โโ๏ธ-MDโ okay so this one is basically-M -MF filein a trench coat ๐ง The driver makes the file name by stripping any directory parts and the suffix off your input file, then tacking on a.depssuffix. ๐-MMDโ same vibe as-MD, but it skips mentioning imported modules that come from the D standard library package directories ๐-Xโ dumps info describing everything in all the source files being compiled, in JSON format, into a file ๐ฆ The driver names it by removing directory components and suffix from the input file, then adding a.jsonsuffix.-Xf fileโ same as-X, but all the JSON goes into the specificfileyou pick ๐-fdocโ generates "Ddoc" documentation and writes it to a file ๐ The compiler names the file by removing directory components and suffix from the input, then adding a.htmlsuffix.-fdoc-dir=dirโ same as-fdoc, but the docs go into the directorydir๐ Pair it with-fdoc-file=fileif you want to set the output file and the directory path separately.-fdoc-file=fileโ same as-fdoc, but the docs go intofile๐๏ธ Pair it with-fdoc-dir=dirto set the file and directory path independently.-fdoc-inc=fileโ tells the compiler to readfileas a Ddoc macro file ๐งฉ You can use multiple-fdoc-incoptions, and the files get read and processed in the same order they were given.
โจ Warnings โจ
Warnings are diagnostic messages that flag constructions that aren't straight-up erroneous but are risky, or that suggest there's probably a bug in the program ๐ Unless -Werror is specified, they won't stop your program from compiling.
-Wallโ turns on all warning messages ๐ Warnings aren't a defined part of the D language, and every construct that might trigger one is still valid code.-Wallocaโ warns on all uses of "alloca" in the source ๐จ-Walloca-larger-than=nโ warns on unbounded uses of alloca, and on bounded uses whose bound can be larger thannbytes.-Wno-alloca-larger-thanturns off-Walloca-larger-thanand is equivalent to-Walloca-larger-than=SIZE_MAXor larger.-Wcast-resultโ warns about casts that will produce a null or zero result โจ Right now it only checks casting between an imaginary and a non-imaginary data type, or casting between a D and C++ class.-Wno-deprecatedโ no warnings about deprecated features and symbols with "deprecated" attributes ๐ โโ๏ธ-Werrorโ turns every warning into an error no cap, this one's strict ๐-Wspeculativeโ lists all error messages from speculative compiles, like__traits(compiles, ...)๐ It doesn't report them as warnings, so they never become errors, even when-Werroris also used.-Wtemplatesโ warns whenever a template instantiation is encountered ๐ง Some coding rules ban templates, so this is a lowkey great way to enforce that rule.-Wunknown-pragmasโ warns when apragma()shows up that gdc doesn'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โ no warnings about questionable usage of the macros used for variable arguments, likeva_start๐ซ-fignore-unknown-pragmasโ turns off errors for unsupported pragmas ๐-fmax-errors=nโ caps the maximum number of error messages atn, and then gdc bails out instead of trying to keep going ๐ Ifnis 0 (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 it with-fdocor-Hto generate files for each module on the command line, but no other output file.-ftransition=idโ reports extra info about D language changes identified byid๐ฎ These values are supported:allโ lists info on all language changes.complexโ lists all usages of complex or imaginary types.dip1000โ implementshttps://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md(Scoped pointers).dip25โ implementshttps://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md(Sealed references).fieldโ lists all non-mutable fields that occupy an object instance.nogcโ lists all hidden GC allocations.tlsโ lists 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, so don't stress about them otherwise.
-defaultlib=libnameโ uses this library instead of libphobos when linking ๐ Options that set the linkage of libphobos, like-static-libphobosor-shared-libphobos, get ignored.-debuglib=libnameโ uses this debug library instead of libphobos when linking ๐ It does nothing unless the-goption was also given on the command line. Options that set the linkage of libphobos, like-static-libphobosor-shared-libphobos, get ignored.-nophoboslibโ no Phobos or D runtime library when linking ๐ซ Options that set the linkage of libphobos, like-static-libphobosor-shared-libphobos, get ignored. The standard system libraries are used normally, unless-nostdlibor-nodefaultlibsis used.-shared-libphobosโ on systems that provide libgphobos and libgdruntime as both a shared and a static library, this forces the shared version ๐ค If no shared version got built when the compiler was configured, it does nothing.-static-libphobosโ on systems that provide libgphobos and libgdruntime as both a shared and a static library, this forces the static version ๐ง If no static version got built when the compiler was configured, it does nothing.
โจ Developer Options โจ
This section is all about command-line options that are mainly for developers or language tooling ๐ ๏ธ
-fdump-d-originalโ outputs the internal front-end AST after the "semantic3" stage ๐ณ This is only useful for debugging the GNU D compiler itself.-vโ dumps info about the compiler's 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 being compiled.
๐ฆ SEE ALSO ๐ฆ
gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entries for gdc and gcc ๐
๐ฅ COPYRIGHT ๐ฅ
Copyright (c) 2006-2021 Free Software Foundation, Inc.
Okay, legal stuff but make it cute ๐ You're allowed 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. There are 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).
That's the whole page, bestie! ๐ซถ It's the gcc-11 build, stamped 2024-07-19. Go be iconic with your D code ๐โจ
๐ฆ where this page comes from
- ubuntu noble: gdc-11-mips-linux-gnu 11.5.0-1ubuntu1~24.04cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms