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 forassertcontracts ๐.-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 aRangeError.-fbounds-check=valueโ An alternative to-fbounds-checkthat 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@safefunctions.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 thecore.stdcpackage 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 anAssertErrorwith extra context information.haltโ halts the program execution.throwโ throws anAssertError(this is the default).
-fdebug,-fdebug=valueโ Turns on compilation of conditionaldebugcode into the program ๐.-fdebugby itself sets the debug level to 1, while-fdebug=enablesdebugcode identified by any of these values:identโ turns on compilation of anydebugcode 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 bystandard๐. 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 ofmoduleor its leftmost part, the file path inspecbecomes 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โ usediras a subdirectory of the gcc directory that holds target-specific D sources and interfaces ๐ธ-iprefix prefixโ setprefixas 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-Ioptions 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.disuffix ๐-Hd dirโ same as-H, but writes the interface files to directorydir. You can pair it with-Hf fileto set the output file and directory path independently โจ-Hf fileโ same as-H, but writes the interface files tofile. You can pair it with-Hd dirto set the output file and directory path independently ๐ฆ-Mโ outputs the module dependencies of all source files being compiled, in a format that works withmake๐ฅ 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-Mor-MM, this specifies a file to write the dependencies to. When used with the driver options-MDor-MMD,-MFoverrides 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-MToptions ๐ฏ-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.depssuffix ๐ฆ-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.jsonsuffix ๐งพ-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.htmlsuffix ๐-fdoc-dir=dirโ same as-fdoc, but writes the documentation to directorydir. You can use it with-fdoc-file=fileto set the output file and directory path independently ๐๏ธ-fdoc-file=fileโ same as-fdoc, but writes the documentation tofile. You can use it with-fdoc-dir=dirto set the output file and directory path independently ๐๏ธ-fdoc-inc=fileโ specifiesfileas a Ddoc macro file to be read. You can use multiple-fdoc-incoptions, and the files are read and processed in the same order ๐-fdump-c++-spec=fileโ for D source files, generates the corresponding C++ declarations infile๐-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 tofile. 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 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-thandisables-Walloca-larger-thanand is equivalent to-Walloca-larger-than=SIZE_MAXor 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-Werroris also used ๐ฎ-Wunknown-pragmasโ warns when apragma()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, likeva_start๐งฉ-fno-ignore-unknown-pragmasโ doesn't recognize unsupported pragmas. Anypragma()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 ton, at which point gdc bails out rather than trying to keep processing the source code. Ifnis0(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-fdocor-Hto generate files for each module on the command line, but no other output file ๐-ftransition=idโ reports additional information about D language changes identified byid. These values are supported:allโ list information on all D language transitionscomplexโ list all usages of complex or imaginary typesfieldโ list all non-mutable fields which occupy an object instanceinโ list all usages of "in" on parameternogcโ list all hidden GC allocationstemplatesโ list statistics on template instantiationstlsโ 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-libphobosor-shared-libphobos, are ignored ๐ซง-debuglib=libnameโ specifies the debug library to use instead of libphobos when linking. This has no effect unless-gwas also given on the command line. Options specifying the linkage of libphobos, like-static-libphobosor-shared-libphobos, are ignored ๐-nophoboslibโ don't use the Phobos or D runtime library when linking. Options specifying the linkage of libphobos, like-static-libphobosor-shared-libphobos, are ignored. The standard system libraries are used normally, unless-nostdlibor-nodefaultlibsis used ๐ซ-shared-libphobosโ on systems that providelibgphobosandlibgdruntimeas 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 providelibgphobosandlibgdruntimeas 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 ๐
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
- ubuntu noble: gdc-14-aarch64-linux-gnu 14-20240412-0ubuntu1cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms