GDC(1)
π GDC(1) Β· GNU π
β¨ NAME β¨
okay bestie, the name card says it all: gdc is 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 up top, so scroll down for the rest π
β¨ DESCRIPTION β¨
gdc is the GNU compiler for D and it's giving GCC energy, so it takes 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 relearn everything β¨
β¨ 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 π
. If you use the -o file option, though, all the input files get compiled together into one single output file named file. That's allowed even with -S or -c πΈ
A D interface file only holds what an import of the module actually needs, not the whole implementation of that module π§ You can make one from a D source file with the -H option. When the compiler resolves an import declaration, it looks for matching .di files first, then .d π
A Ddoc source file has code written in the D macro processor language. It's mainly for making user docs out of embedded comments, with a little HTML-generation vibe π If a .d source file starts with the string "Ddoc", it gets treated as general purpose documentation instead of D source code π¦
π 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 code for declarations that were 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, which can give performance a real boost for code that leans on arrays π₯
β οΈ Heads up bestie: if your code actually breaks array bounds, this can lead to unpredictable behavior. It's only safe to use if you're totally sure your code never throws a RangeError π
-fbounds-check=valueβ The more flexible cousin of-fbounds-check, letting you pick exactly where bounds checking is on or off. The supported values are: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 thecore.stdcpackage is a built-in function β¨-fdebug,-fdebug=valueβ Turns on compilation of conditionaldebugcode into the program. The plain-fdebugoption sets the debug level to 1, while-fdebug=enablesdebugcode identified by any of these values:levelβ Sets the debug level to level, so anydebugcode<=level gets compiled in.identβ Turns on compilation of anydebugcode identified by ident.
-fno-druntimeβ Implements the BetterC spec athttps://dlang.org/spec/betterc.htmlπ It assumes compilation targets an environment with no D runtime library.
This is equivalent to compiling with the following options:
gdc -nophoboslib -fno-exceptions -fno-moduleinfo -fno-rtti
-fno-invariantsβ Turns off code generation for classinvariantcontracts.-fno-moduleinfoβ Turns off generation ofModuleInfoand the related functions that would become unreferenced without it, which may allow linking to programs not written in D π§ The functions that don't get 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 byfilename.-fno-postconditionsβ Turns off code generation for postconditionoutcontracts.-fno-preconditionsβ Turns off code generation for preconditionincontracts.-freleaseβ Turns on release mode, which means no runtime checks for contracts and asserts π« Array bounds checking isn't done for@systemand@trustedfunctions.
π¨ In this mode, assertion failures are undefined behavior. Not a vibe.
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 that info will result in an error π-fno-switch-errorsβ Controls what code gets generated when no case is matched in afinal switchstatement. The default run-time behavior is to throw aSwitchError. Turning off-fswitch-errorsmeans the execution of the program is immediately halted instead π-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 these values:levelβ Sets the version level to level, so anyversioncode>=level gets compiled in.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 π By default, all public symbols are emitted as weak, unless the target doesn't support weak symbols. With this disabled, common symbols are instead put in COMDAT or become private.-MDβ okay so this is basically-M -MF file, bestie! π«Ά The driver figures out the file name by stripping any directory parts and the suffix from the input file, then tacks on a.depssuffix.-MMDβ like-MD, but it doesn't 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, into a file. The driver picks that file 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 exactfileyou name. β¨-fdocβ generates "Ddoc" documentation and writes it to a file. The compiler names it by removing directory components and the suffix from the input file, 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 directory path separately. π-fdoc-file=fileβ same as-fdoc, but the docs get written tofile. Pair it with-fdoc-dir=dirto set the file and directory independently. π-fdoc-inc=fileβ tells the compiler to readfileas a Ddoc macro file. You can use multiple-fdoc-incoptions, and they get read and processed in the order you gave them. π
β οΈ Warnings
Okay, warnings are diagnostic messages about constructions that aren't straight-up erroneous, but that are risky or 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 a warning is still valid code. π¦-Wallocaβ warns on all uses ofallocain the source. π₯-Walloca-larger-than=nβ warns on unbounded uses ofalloca, 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 this only happens when casting between an imaginary and non-imaginary data type, or casting between a D and C++ class. β¨-Wno-deprecatedβ stops the warnings about deprecated features and symbols withdeprecatedattributes. π«-Werrorβ turns every warning into an error. Literally no mercy. π-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.
Lowkey the big catch with-Wspeculative: those messages never turn into errors, even with-Werroron. π
-Wtemplatesβ warns when a template instantiation is encountered. Some coding rules ban templates, so you can use this 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β stops the warnings about questionable usage of the macros used to handle variable arguments, likeva_start. π-fignore-unknown-pragmasβ turns off errors for unsupported pragmas. π«Ά-fmax-errors=nβ caps the number of error messages atn, and then gdc bails out instead of trying to keep going through the source code. 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 information 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 waste your time on them otherwise. π₯²
-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. Options that set the linkage of libphobos, like-static-libphobosor-shared-libphobos, get ignored. π-nophoboslibβ don't use the 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 still get 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 was built when the compiler was configured, this 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, this does nothing. π§
π οΈ Developer Options
This section covers command-line options that are mainly of interest to developers or language tooling. Main character energy for the nerds π€π
-fdump-d-originalβ outputs the internal front-end AST after the "semantic3" stage. This is only useful for debugging the GNU D compiler itself, so unless you're doing that, it's not for you, babe. π ββοΈ-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 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. π
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). π«Ά
And that's a wrap, bestie! π This page is giving gcc-11 energy, last dated 2024-07-19, and I'm obsessed. πβ¨
π¦ where this page comes from
- ubuntu questing: gdc-11-sparc64-linux-gnu 11.5.0-7ubuntu1cross1
- ubuntu resolute: gdc-11-sparc64-linux-gnu 11.5.0-11ubuntu2cross1
- ubuntu stonking: gdc-11-sparc64-linux-gnu 11.5.0-11ubuntu2cross1
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms