GDC(1)
๐ GDC(1) ยท GNU Manual ๐
โจ 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...
Only the most useful options are listed here, so scroll down for the rest ๐
๐ธ DESCRIPTION ๐ธ
okay so gdc is the GNU compiler for the D language, and it's giving very familiar energy because it supports a lot of the same options as gcc โจ This manual only covers the options that are specific to gdc, so you don't have to re-learn everything ๐ซถ
๐ฆ OPTIONS ๐ฆ
๐ Input and Output files
For any given input file, the file name suffix decides what kind of compilation happens. These are the input file names that are supported:
file.dโ D source files, the main event ๐file.ddโ Ddoc source filesfile.diโ D interface files
You can pass more than one input file on the gdc command line, and each one gets compiled separately. If you use the "-o file" option, though, all the input files get compiled together and you end up with one single output file, named file. This works even with "-S" or "-c" ๐ฅ
A D interface file only has what an import of the module needs, not the whole implementation of that module, so it's like a lighter version ๐ You can make one with gdc from a D source file by using the "-H" option. When the compiler resolves an import declaration, it looks for matching .di files first, and then for .d โจ
A Ddoc source file has code in the D macro processor language. It's mainly made for turning embedded comments into user documentation, and it's leaning towards 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 me, treating my docs like code ๐
๐ฅ Runtime Options
These options change how programs compiled with gdc behave at runtime, so they're lowkey important ๐
-fall-instantiationsโ Generates code for all template instantiations. By default, the template emission strategy doesn't 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 ๐-fno-assertโ Turns off code generation for"assert"contracts ๐ โโ๏ธ-fno-bounds-checkโ Turns off array bounds checking for all functions. This can improve performance for code that uses arrays a lot. Heads up, though: if the code actually does violate array bounds constraints, you can get unpredictable behavior. It's only safe to use this 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 is turned on or off. These values are supported:onโ Turns on array bounds checking for all functionssafeonlyโ Turns on array bounds checking only for@safefunctionsoffโ 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 the program. The-fdebugoption by itself sets the debug level to 1.-fdebug=enables"debug"code identified by any of these values:levelโ Sets the debug level tolevel, so any"debug"code<= levelgets compiled inidentโ Turns on compilation of any"debug"code identified byident
-fno-druntimeโ Implementshttps://dlang.org/spec/betterc.html. It assumes compilation is targeting an environment without a D runtime library, which is giving bare-metal vibes ๐ธ This is equivalent to compiling with the following 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"and related functions that would become unreferenced without it. This might let you link to programs that aren't written in D โจ The functions that won't be 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. > Undefined behavior, bestie. Be careful with this one ๐ญ
This is equivalent to compiling with the following 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โ Controls what code gets generated when no case is matched in a"final switch"statement. The default runtime behavior is to throw a"SwitchError". Turning off-fswitch-errorsmeans that the program's execution gets immediately halted instead ๐-funittestโ Turns on compilation of"unittest"code and turns on the"version(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, so any"version"code>= levelgets compiled inidentโ Turns on compilation of"version"code identified byident
-fno-weakโ Turns off emission of instantiated declarations that can be defined in multiple objects as weak or one-only 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 itself ๐งญ
-Idirโ Specifies a directory to use when searching for imported modules at compile time. You can use multiple-Ioptions, and the paths get searched in the same order they were given ๐-Jdir(the-Jswitch with itsdirargument) โ Specifies a directory to use when searching for files in string imports at compile time. This switch is required if you want 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โ Manipulates file paths of imported modules. If an imported module matches all or the leftmost part ofmodule, the file path inspecgets used as the location to search for D sources. This is useful when your 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 shown 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 target-specific D sources and interfaces ๐ท-iprefix prefixโ Specifiesprefixas the prefix for thegccdirectory that holds target-specific D sources and interfaces. If the prefix represents a directory, make sure you include the final'/'๐-nostdincโ Doesn't search the standard system directories for D source and interface files. Only the directories specified with-Ioptions (plus the directory of the current file, if appropriate) get searched ๐ โโ๏ธ-MDโ okay this one is basically-M -MF filein a trench coat ๐งฅ. The driver works out the file name by stripping any directory components and the suffix off the input file, then slapping a.depssuffix on the end ๐-MMDโ like-MD, but it doesn't mention imported modules from the D standard library package directories ๐ฆ-Xโ dumps info describing the contents of every source file being compiled into a JSON file. The driver picks the name by removing directory components and the suffix from the input file, then adding a.jsonsuffix ๐งพ-Xf fileโ same energy as-X, but all the JSON goes into the file you name ๐-fdocโ generates "Ddoc" documentation and writes it to a file. The compiler builds the name by removing directory components and suffix from the input file, then adding.html๐-fdoc-dir=dirโ same as-fdoc, but the docs go into directory dir. Pair it with-fdoc-file=fileif you want to set the output file and directory path separately ๐๏ธ-fdoc-file=fileโ same as-fdoc, but the docs go into file. Pair it with-fdoc-dir=dirto set the file and directory independently ๐ธ-fdoc-inc=fileโ tells it to read file as a Ddoc macro file. You can stack multiple-fdoc-incoptions, and the files get read and processed in the order you gave them ๐งฉ
โ ๏ธ Warnings
Warnings are diagnostic messages about constructions that aren't straight-up erroneous, but are risky or hint that 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 could trigger one is still valid code ๐-Wallocaโ warns on all uses ofallocain the source ๐-Walloca-larger-than=nโ warns on unbounded uses ofalloca, plus bounded uses whose bound can be larger than n bytes.-Wno-alloca-larger-thanturns off 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 checked for casting between an imaginary and non-imaginary data type, or between a D and C++ class โจ-Wno-deprecatedโ don't warn about deprecated features and symbols with"deprecated"attributes ๐-Werrorโ turns every warning into an error. Harsh, but iconic ๐ฅ-Wspeculativeโ lists all error messages from speculative compiles, like__traits(compiles, ...). It doesn't report these 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, and this is how you 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 ๐-fignore-unknown-pragmasโ turns off errors for unsupported pragmas ๐ฆ-fmax-errors=nโ caps the number of error messages at n, and then gdc bails out instead of trying to keep going through the source code. If n is 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 combine 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 by id. These values are supported:allโ list info on all language changes ๐checkimportsโ give deprecation messages about-ftransition=importanomalies ๐complexโ list all usages of complex or imaginary types ๐งฎdip1000โ implements<https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md>(Scoped pointers) ๐dip25โ implements<https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md>(Sealed references) ๐ซงfieldโ list all non-mutable fields that occupy an object instance ๐งimportโ tells the compiler to go back to the old lookup behavior for resolving unqualified symbol names, which happened in a single pass and ignored any protection attributes. The default lookup strategy uses two passes: the first ignores imported declarations, and the second only looks at imports. The protection ("private","package","protected") of symbols is also enforced to sort out conflicts between private and public symbols ๐ฐ๏ธnogcโ list all hidden GC allocations ๐๏ธtlsโ list all variables going into thread local storage ๐งต
Options for Linking
These options only matter when the compiler links object files into an executable output file. If the compiler isn't doing a link step, they're meaningless ๐
-defaultlib=libnameโ specifies the library to use instead of libphobos when linking. Options that set the linkage of libphobos, like-static-libphobosor-shared-libphobos, get ignored ๐-debuglib=libnameโ specifies the debug library to use instead of libphobos when linking. This does nothing unless the-goption was also given on the command line. Linkage options like-static-libphobosor-shared-libphobosare ignored ๐-nophoboslibโ don't use the Phobos or D runtime library when linking. Linkage options like-static-libphobosor-shared-libphobosare ignored. The standard system libraries get used as normal, 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 was 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 was built when the compiler was configured, it does nothing ๐ชจ
Developer Options
This section covers 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 your 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-2020 Free Software Foundation, Inc. ๐
Okay, so you're allowed to copy, distribute, and/or modify this document under 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 in the man page gfdl(7) ๐ซถ
That's the whole page, bestie ๐ You now have the gcc-10 GDC(1) page from 2023-07-07 in your brain forever โจ๐
๐ฆ where this page comes from
- ubuntu jammy: gdc-10-m68k-linux-gnu 10.5.0-1ubuntu1~22.04cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms