GDC(1)

πŸ“¦
version 13.3.0 Β· 3 versions
, in ubuntu noble

πŸ’– GDC β€” bestie edition πŸ’–

okay so this is the gdc manual page, from the GNU manual, section 1. yes it's long. no we're not skipping anything. grab a snack. πŸ“


✨ 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...

Only the most useful options are listed up there, bestie β€” see below for the rest of them. there are SO many more. we'll get to them. 🫢


✨ DESCRIPTION ✨

The gdc command is the GNU compiler for the D language, and it supports many of the same options as gcc. This manual only documents the options specific to gdc. lowkey important: it's only the gdc-specific ones here, so if you're looking for the gcc-flavoured stuff, that's a different page, iykyk. 😌


✨ OPTIONS ✨

πŸŽ€ Input and Output files

So for any given input file, the file name suffix decides what kind of compilation happens. it's giving "your file 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 put more than one input file on the gdc command line, and each one gets compiled separately in the compilation process. and if you pass a -o file option, then all the input files get compiled together, producing a single output file, named file. 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 entire 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. order matters, bestie. πŸ¦‹

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 plot twist: if a .d source file starts with the string "Ddoc", then it's treated as general purpose documentation, not as a D source file. sneaky. πŸ’€


🌸 Runtime Options

These options affect the runtime behavior of programs compiled with gdc. so like, how your program behaves when it actually runs. yes we're going there.

  • -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.
  • -fno-assert β€” Turn off code generation for assert contracts. bye bye asserts. πŸ™ˆ
  • -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 are sure that your code never throws a RangeError.
⚠️ okay so real talk: turning this off when your code does go out of bounds = unpredictable behavior. only do it if you're certain your code never throws a RangeError. don't be brave for no reason. 😭
  • -fbounds-check=value β€” An alternative to -fbounds-check that 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 @safe functions.
    • 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 the core.stdc package 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 an AssertError with extra context information.
    • halt β€” Halt the program execution.
    • throw β€” Throw an AssertError (the default).
  • -fdebug
  • -fdebug=value β€” Turn on compilation of conditional debug code into the program. The -fdebug option itself sets the debug level to 1, while -fdebug= enables debug code that are identified by any of the following values:
    • ident β€” Turns on compilation of any debug code 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") to 199711.
    • c++11 β€” Sets __traits(getTargetInfo, "cppStd") to 201103.
    • c++14 β€” Sets __traits(getTargetInfo, "cppStd") to 201402.
    • c++17 β€” Sets __traits(getTargetInfo, "cppStd") to 201703. This is the default.
    • c++20 β€” Sets __traits(getTargetInfo, "cppStd") to 202002.
  • -fno-invariants β€” Turns off code generation for class invariant contracts.
  • -fmain β€” Generates a default main() 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 when main is already defined in user code.
  • -fno-moduleinfo β€” Turns off generation of the ModuleInfo and 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 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 by filename.
  • -fno-postconditions β€” Turns off code generation for postcondition out contracts.
  • -fno-preconditions β€” Turns off code generation for precondition in contracts.
  • -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.
    • 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 @nogc code).
    • 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 for alias this before searching in upper scopes.
    • fiximmutableconv β€” Disallows unsound immutable conversions that were formerly incorrectly permitted.
    • in β€” Implements in parameters to mean scope const [ref] and accepts rvalues.
    • inclusiveincontracts β€” Implements in contracts of overridden methods to be a superset of parent contract.
    • nosharedaccess β€” Turns off and disallows all access to shared memory objects.
    • rvaluerefparam β€” Implements rvalue arguments to ref parameters.
    • systemvariables β€” Disables access to variables marked @system from @safe code.
  • -frelease β€” Turns on compiling in release mode, which means not emitting runtime checks for contracts and asserts. Array bounds checking is not done for @system and @trusted functions, 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:
  • -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. 😭
  • -fno-switch-errors β€” This option controls what code is generated when no case is matched in a final switch statement. The default run time behavior is to throw a SwitchError. Turning off -fswitch-errors means that instead the execution of the program is immediately halted. πŸ’€
  • -funittest β€” Turns on compilation of unittest code, and turns on the version(unittest) identifier. This implies -fassert. slay, test your code bestie. ✨
  • -fversion=value β€” Turns on compilation of conditional version code into the program identified by any of the following values:
    • ident β€” Turns on compilation of version code 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 in COMDAT or become private.

These options specify directories to search for files, libraries, and other parts of the compiler. basically: "where do I look for my stuff." πŸ”

  • -Idir β€” Specify a directory to use when searching for imported modules at compile time. Multiple -I options can be used, and the paths are searched in the same order.
  • -Jdir β€” Specify a directory to use when searching for files in string imports at compile time. This switch is required in order to use import(file) expressions. Multiple -J options can be used, and the paths are searched in the same order.

🫢 bestie there's MORE. this page keeps going. stay with me, part 2 is coming. πŸ’–
  • -Ldir β€” when you're linking, this says "hey, also look in dir for libraries," same energy as gcc πŸ’–
  • -Bdir β€” tells the compiler where to find its own executables, libraries, source files and data files, just like gcc does 🫢
  • -fmodule-file=module=spec β€” okay bestie, this one massages the file paths of imported modules. If an imported module matches all of module, or just the leftmost part of it, then the file path in spec becomes the spot to search for D sources. You use this when your source file paths and names don't line up with the package and module hierarchy. Lowkey the examples make it click:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar

That tells the compiler: search all import paths for the source file foo.d when importing A.B, and the directory bar/ when importing C, exactly like this D code annotates:

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. If that prefix is a directory, you gotta include the final / fr πŸ’…
  • -nostdinc β€” do not go searching the standard system directories for D source and interface files. Only the directories you named with -I options get searched (plus the directory of the current file, if that's appropriate) 🌸

🌈 Code Generation 🌈

Besides the many gcc options that control code generation, gdc has several options that are just its own thing πŸ’…

  • -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 on a .di suffix πŸŽ€
  • -Hd dir β€” same as -H, but it writes those interface files to directory dir. You can pair this with -Hf file to set the output file and the directory path independently πŸ‘‘
  • -Hf file β€” same as -H but it writes interface files to file. Pair it with -Hd dir to set the output file and the directory path independently πŸ’–
  • -M β€” outputs the module dependencies of all source files being compiled, in a format that make can eat. The compiler spits out one make rule containing the object file name for that source file, a colon, and the names of all the imported files 🌟
  • -MM β€” like -M but it does not mention imported modules from the D standard library package directories πŸ™ˆ
  • -MF file β€” when you use it with -M or -MM, it names a file to write the dependencies to. When you use it with the driver options -MD or -MMD, -MF overrides the default dependency output file πŸ¦‹
  • -MG β€” this option exists 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 one depend on nothing ✨
  • -MT target β€” change the target of the rule emitted by dependency generation to be exactly the string you specify. Want multiple targets? Pass them as a single argument to -MT, or just use multiple -MT options, your call 🫢
  • -MQ target β€” same as -MT, except it quotes any characters that are special to make πŸ’…
  • -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 .deps suffix 🌸
  • -MMD β€” like -MD but 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 .json suffix πŸ’–
  • -Xf file β€” same as -X, but it writes all that JSON content to the file you specify ✨
  • -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 a .html suffix πŸŽ€
  • -fdoc-dir=dir β€” same as -fdoc, but it writes documentation to directory dir. Pair it with -fdoc-file=file to set the output file and the directory path independently πŸ‘‘
  • -fdoc-file=file β€” same as -fdoc, but it writes documentation to file. Pair it with -fdoc-dir=dir to set the output file and the directory path independently πŸ’œ
  • -fdoc-inc=file β€” specify file as a Ddoc macro file to be read. You can stack multiple -fdoc-inc options, and the files get read and processed in the same order 🌟
  • -fdump-c++-spec=file β€” for D source files, generate the corresponding C++ declarations into file πŸ¦‹
  • -fdump-c++-spec-verbose β€” used together with -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. Super useful for debugging compilation errors, and it gives debuggers source to show when they ask for it 🫢

πŸ’€ Warnings πŸ’€

Warnings are diagnostic messages that report constructions that aren't inherently erroneous but that are risky, or that suggest there's probably a bug lurking in the program. Unless you pass -Werror, they do not stop the program from compiling, bestie πŸ‘‘

  • -Wall β€” turns on all warning messages. Warnings are not a defined part of the D language, and every construct that might generate a warning here is still valid code ✨
  • -Walloca β€” this one 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. -Wno-alloca-larger-than disables the -Walloca-larger-than warning and is equivalent to -Walloca-larger-than=SIZE_MAX or larger πŸ’…
  • -Wno-builtin-declaration-mismatch β€” warns if a built-in function is declared with an incompatible signature 🌸
  • -Wcast-result β€” warns about casts that will produce a null or zero result. Right now this only happens for casting between an imaginary and non-imaginary data type, or casting between a D and C++ class πŸ’–
  • -Wno-deprecated β€” don't warn about usage of deprecated features and symbols that carry "deprecated" attributes πŸ™ˆ
  • -Werror β€” turns all warnings into errors. no cap πŸ”₯
  • -Wextra β€” this enables some extra warning flags that -Wall doesn't turn on:
    • -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 πŸ‘‘
  • -Wspeculative β€” lists all error messages from speculative compiles, like __traits(compiles, ...). Heads up: this option does not report messages as warnings, so these messages never become errors even when you also use -Werror πŸ¦‹
  • -Wunknown-pragmas β€” warns when a pragma() shows up that gdc doesn't understand. This differs from -fignore-unknown-pragmas, where a pragma that is part of the D language but just isn't implemented by the compiler won't get reported πŸ’…
  • -Wno-varargs β€” don't 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 maximum number of error messages at n, at which point gdc bails out instead of trying to keep processing the source code. If n is 0 (which is 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 -fdoc or -H to generate files for each module present on the command-line, but no other output file πŸ’–
  • -ftransition=id β€” reports extra 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. They're meaningless if the compiler isn't doing a link step, periodt πŸ’…

  • -defaultlib=libname β€” specify the library to use instead of libphobos when linking. Options that specify the linkage of libphobos, like -static-libphobos or -shared-libphobos, get ignored πŸ‘‘
  • -debuglib=libname β€” specify the debug library to use instead of libphobos when linking. This has no effect unless you also gave the -g option on the command line. Options specifying the linkage of libphobos, like -static-libphobos or -shared-libphobos, get ignored 🌸
  • -nophoboslib β€” do not use the Phobos or D runtime library when linking. Options specifying the linkage of libphobos, like -static-libphobos or -shared-libphobos, get ignored. The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used πŸ’–
  • -shared-libphobos β€” on systems that provide libgphobos and libgdruntime as 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 provide libgphobos and libgdruntime as 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 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 β€” okay bestie, this one is the gossip mode for the compiler πŸ’… it dumps all the info about the compiler language processing stages while your source program is being compiled. So what's in the dump? literally everything: a list of all the modules getting processed through the "parse", "semantic", "semantic2", and "semantic3" stages, plus all the "import" modules and their file paths, plus all the "function" bodies that are being compiled. it's giving backstage pass energy fr fr πŸ”₯

πŸ‘€ SEE ALSO (go read these too bestie) πŸ‘€

and also the Info entries for gdc and gcc. that's the whole squad 🫢 go say hi πŸ’–


Copyright (c) 2006-2023 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). πŸ“œβœ¨

no cap, that's the real license text up there β€” don't skip it, it's doing important main character work 😌

and that's a wrap on the whole page, bestie 🌸 this edition is gcc-13, dated 2024-09-04, and it lives in section GDC(1). periodt πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from