GDC(1)

โœจ GDC(1) โœจ

okay bestie, this manual page is from the GNU crew ๐ŸŒˆ and it's all about gdc. Let's get into it ๐Ÿ’…

โœจ 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 ๐Ÿงš the rest are down below, so keep scrolling!

โœจ DESCRIPTION โœจ

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're not going to get bored with repeats ๐Ÿฆ‹.

โœจ OPTIONS โœจ

๐ŸŒธ Input and Output files

Okay so, for any input file, the file name suffix decides what kind of compilation happens ๐Ÿ‘‘. These are the input file names that work:

  • file.d โ€” D source files.
  • file.dd โ€” Ddoc source files.
  • file.di โ€” D interface files.

You can throw more than one input file onto 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. This is allowed even when you're using -S or -c โœจ.

A D interface file only has what an import of the module actually needs, not the whole implementation of that module ๐Ÿซถ. gdc can make these from a D source file if you use the -H option. When the compiler resolves an import declaration, it looks for matching .di files first, and then it checks for .d files ๐Ÿ”ฅ.

A Ddoc source file has code written in the D macro processor language. It's mainly made for turning embedded comments into user documentation, with a slight lean toward HTML generation ๐Ÿ“. If a .d source file starts with the string Ddoc, it's treated as general purpose documentation instead of as a D source file. Not me, but iykyk ๐Ÿ™ˆ.

๐ŸŒˆ Runtime Options

These options change how programs compiled with gdc behave at runtime โญ.

  • -fall-instantiations โ€” Generates code for all template instantiations ๐Ÿฆ‹. By default, the compiler skips 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 for assert contracts ๐Ÿ™ˆ.
  • -fno-bounds-check โ€” Turns off array bounds checking for all functions, which can boost performance for code that uses arrays a lot ๐Ÿš€. Heads up ๐Ÿ’€: this can lead to unpredictable behavior if the code in question actually does violate array bounds constraints. It's only safe if you're totally sure your code never throws a RangeError.
  • -fbounds-check=value โ€” An alternative to -fbounds-check that gives you more control over where bounds checking is turned on or off ๐ŸŽฏ. These values work:
    • 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 โ€” Doesn'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 โ€” Controls what code gets generated when an assertion, bounds check, or final switch fails ๐Ÿ˜ญ. These values are supported:
    • context โ€” throws an AssertError with extra context information.
    • halt โ€” halts the program execution.
    • throw โ€” throws an AssertError (this is the default).
  • -fdebug, -fdebug=value โ€” Turns on compilation of conditional debug code into the program ๐Ÿ”. -fdebug by itself sets the debug level to 1, while -fdebug= enables debug code identified by any of these values:
    • ident โ€” turns on compilation of any debug code identified by ident.
  • -fno-druntime โ€” Implements <https://dlang.org/spec/betterc.html> ๐Ÿงš. It assumes 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 ๐Ÿ‘‘. These 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.
  • -Ldir โ€” okay so when you're linking, this lets you point at a library search directory, same as gcc ๐Ÿฆ‹
  • -Bdir โ€” tells the compiler where to find its own stuff: executables, libraries, source files, and data files. Also same as gcc ๐Ÿงš
  • -fmodule-file=module=spec โ€” lowkey a lifesaver ๐Ÿ’… This one messes with the file paths of imported modules. If an imported module matches all of module or its leftmost part, the file path in spec becomes the place it searches for D sources. You'd use this when your source file paths and names don't match your package and module hierarchy. Check these out:
gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar

So this tells the compiler to search all import paths for foo.d when importing A.B, and to check the bar/ directory when importing C. Here's how it plays out in D code:

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 that same gcc directory of target-specific D sources and interfaces. If the prefix is a directory, make sure you include the final / ๐Ÿซถ
  • -nostdinc โ€” don't search the standard system directories for D source and interface files ๐Ÿ™… Only the directories given with -I options get searched (plus the directory of the current file, if that applies).

๐ŸŽ€ Code Generation ๐ŸŽ€

Besides all the usual gcc options for code generation, gdc has a few of its own, bestie ๐Ÿ’–

  • -H โ€” generates D interface files for all modules being compiled. The compiler works out the output file from the input file name, strips any directory components and suffix, and slaps on the .di suffix ๐Ÿ“
  • -Hd dir โ€” same as -H, but writes the interface files to directory dir. You can pair it with -Hf file to set the output file and directory path independently โœจ
  • -Hf file โ€” same as -H, but writes the interface files to file. You can pair it with -Hd dir to set the output file and directory path independently ๐Ÿฆ‹
  • -M โ€” outputs the module dependencies of all source files being compiled, in a format that works with make ๐Ÿ”ฅ It spits out one make rule containing the object file name for that source file, a colon, and the names of all imported files.
  • -MM โ€” like -M, but doesn't mention imported modules from the D standard library package directories ๐Ÿ™ˆ
  • -MF file โ€” when used with -M or -MM, this specifies a file to write the dependencies to. When used with the driver options -MD or -MMD, -MF overrides the default dependency output file ๐ŸŒˆ
  • -MG โ€” this one's just for compatibility with gcc, so the compiler ignores it ๐Ÿคท
  • -MP โ€” outputs a phony target for each dependency other than the modules being compiled, causing each one to depend on nothing ๐Ÿ‘ป
  • -MT target โ€” changes the target of the rule emitted by dependency generation to be exactly the string you specify. If you want multiple targets, you can specify them as a single argument to -MT, or use multiple -MT options ๐ŸŽฏ
  • -MQ target โ€” same as -MT, but it quotes any characters that are special to make ๐Ÿ’œ
  • -MD โ€” this is equivalent to -M -MF file. The driver works out the file by removing any directory components and suffix from the input file, then adding a .deps suffix ๐Ÿ“ฆ
  • -MMD โ€” like -MD, but 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, to a file. The driver figures out the file by removing directory components and suffix from the input file, then adding a .json suffix ๐Ÿงพ
  • -Xf file โ€” same as -X, but writes all the JSON contents to the file you specify ๐Ÿ’…
  • -fdoc โ€” generates "Ddoc" documentation and writes it to a file. The compiler determines the file by removing directory components and suffix from the input file, then adding a .html suffix ๐Ÿ“š
  • -fdoc-dir=dir โ€” same as -fdoc, but writes the documentation to directory dir. You can use it with -fdoc-file=file to set the output file and directory path independently ๐Ÿ—‚๏ธ
  • -fdoc-file=file โ€” same as -fdoc, but writes the documentation to file. You can use it with -fdoc-dir=dir to set the output file and directory path independently ๐Ÿ—ƒ๏ธ
  • -fdoc-inc=file โ€” specifies file as a Ddoc macro file to be read. You can use multiple -fdoc-inc options, and the files are read and processed in the same order ๐Ÿ“–
  • -fdump-c++-spec=file โ€” for D source files, generates the corresponding C++ declarations in file ๐ŸŒŸ
  • -fdump-c++-spec-verbose โ€” used alongside -fdump-c++-spec= above, this 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. This is super useful for debugging compile errors, and gives debuggers source to show when requested ๐Ÿ›

๐Ÿšจ Warnings ๐Ÿšจ

Warnings are diagnostic messages that flag constructions which aren't inherently erroneous, but are risky or suggest there's likely 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 may 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 than n bytes. -Wno-alloca-larger-than disables -Walloca-larger-than 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 is only done 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 with "deprecated" attributes ๐Ÿ™…
  • -Werror โ€” turns all warnings into errors ๐Ÿšซ
  • -Wextra โ€” enables some extra warning flags that are not enabled by -Wall. It adds -Waddress -Wcast-result -Wmismatched-special-enum -Wunknown-pragmas โœจ
  • -Wmismatched-special-enum โ€” warns when an enum the compiler recognizes as special is declared with a different size than the built-in type it represents ๐Ÿ“
  • -Wspeculative โ€” lists all error messages from speculative compiles, such as __traits(compiles, ...). This option doesn't report messages as warnings, so these messages never become errors when -Werror is also used ๐Ÿ”ฎ
  • -Wunknown-pragmas โ€” warns when a pragma() is encountered that isn't understood by gdc. This differs 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 โ€” don't warn about questionable usage of the macros used to handle variable arguments, like va_start ๐Ÿงฉ
  • -fno-ignore-unknown-pragmas โ€” doesn't recognize unsupported pragmas. Any pragma() encountered that isn't part of the D language will result in an error
โš ๏ธ Deprecation alert: this option is now deprecated and will be removed in a future release.
  • -fmax-errors=n โ€” limits the maximum number of error messages to n, at which point gdc bails out rather than trying to keep processing the source code. If n is 0 (the default), there is no limit on the number of error messages produced ๐Ÿ›‘
  • -fsyntax-only โ€” checks the code for syntax errors, but doesn't actually compile it. This can be used with -fdoc or -H to generate files for each module on the command line, but no other output file ๐Ÿ“
  • -ftransition=id โ€” reports additional information about D language changes identified by id. These values are supported:
    • 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 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 ๐Ÿฅบ

  • -defaultlib=libname โ€” specifies the library to use instead of libphobos when linking. Options specifying the linkage of libphobos, like -static-libphobos or -shared-libphobos, are ignored ๐Ÿซง
  • -debuglib=libname โ€” specifies the debug library to use instead of libphobos when linking. This has no effect unless -g was also given on the command line. Options specifying the linkage of libphobos, like -static-libphobos or -shared-libphobos, are ignored ๐Ÿž
  • -nophoboslib โ€” don't use the Phobos or D runtime library when linking. Options specifying the linkage of libphobos, like -static-libphobos or -shared-libphobos, are ignored. The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used ๐Ÿšซ
  • -shared-libphobos โ€” on systems that provide libgphobos and libgdruntime as a shared and a static library, this 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 a shared and a static library, this 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 language tooling ๐Ÿ’œ

  • -fdump-d-original ๐Ÿ” โ€” okay bestie, this one dumps the internal front-end AST right after the "semantic3" stage. It's only useful for debugging the GNU D compiler itself ๐Ÿ’€, so unless you're literally building the compiler, you can let this one sleep ๐Ÿ˜ด.
  • -v ๐ŸŽ€ โ€” this is the chatty one! While your source program is being compiled, it spills the tea on the compiler's language processing stages. It lists every module that goes through the "parse", "semantic", "semantic2", and "semantic3" stages ๐Ÿงš, every "import" module along with its file path ๐Ÿ—‚๏ธ, and every "function" body being compiled โœจ.

๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

Go check these out, they're giving useful info ๐Ÿ“š: gpl(7), gfdl(7), fsf-funding(7), gcc(1), and the Info entries for gdc and gcc.

Copyright (c) 2006-2024 Free Software Foundation, Inc. ๐Ÿ’œ

Okay so the legal part is actually super chill ๐Ÿซถ. 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 included in the man page gfdl(7) ๐Ÿ“œ.


And that's the whole page, bestie! ๐Ÿ’– It came from gcc-14 and is dated 2024-04-12, so you officially know more about GDC than most people ๐Ÿ‘‘๐ŸŒˆ slay forever ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from