GDC(1)
π GDC(1) Β· GNU Manual π (part 1 of 2)
β¨ NAME β¨
gdc is a GCC-based compiler for the D language, and it's giving main character energy π
β¨ SYNOPSIS β¨
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
okay so this is just the cheat sheet π Only the most useful options are listed here, so scroll down for the rest π
β¨ DESCRIPTION β¨
The gdc command is the GNU compiler for the D language, and it slays because it supports a lot of the same options as gcc πΈ This manual only covers the options that are specific to gdc π«Ά
β¨ OPTIONS β¨
π¦ Input and Output files
For any input file, the file name suffix decides what kind of compilation happens π₯ These are the kinds of input file names 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 -o file, then all the input files get compiled together and produce one single output file called file β¨ That works even with -S or -c, so no stress π
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 searches for matching .di files first, and then for .d files π
A Ddoc source file has code in the D macro processor language π It's mainly for making user documentation out of embedded comments, with a slight HTML-generation crush π If a .d source file starts with the string "Ddoc", then it's 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 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 ποΈ This can boost performance for code that uses arrays a lot π¨
β οΈ Heads up: if the code actually violates array bounds, this can lead to unpredictable behavior. It's only safe to use 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 functions.safeonlyβ turns on array bounds checking only for@safefunctions.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 recognizes when a function in thecore.stdcpackage is a built-in function β¨-fdebug,-fdebug=valueβ turns on compiling conditionaldebugcode into the program π-fdebugby itself sets the debug level to 1, while-fdebug=enablesdebugcode identified by any of these values:levelβ sets the debug level tolevel, so anydebugcode<= levelgets compiled in.identβ turns on compilation of anydebugcode identified byident.
-fno-druntimeβ implements<https://dlang.org/spec/betterc.html>π It assumes the compilation targets an environment without a D runtime library π΅ This is equivalent to compiling with these 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 π§Ή This may allow linking to programs that aren't written in D π The functions that are not 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 emitted runtime checks for contracts and asserts. Array bounds checking isn't done for@systemand@trustedfunctions, and assertion failures are undefined behavior π
π Undefined behavior alert: assertion failures in release mode are undefined behavior, so be extra careful, bestie.
This is equivalent to compiling with these 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 requiring 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 tolevel, so anyversioncode>= levelgets compiled in.identβ turns on compilation ofversioncode 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 lacks support for weak symbols πͺ Disabling this option means common symbols are instead put in COMDAT or become private π
πΊοΈ Options for Directory Search
These options tell the compiler which directories to search for files, libraries, and other parts of the compiler itself πΊοΈ
-Idirβ a directory to use when searching for imported modules at compile time π Multiple-Ioptions can be used, and the paths get searched in the same order π-Jdirβ a directory to use when searching for files in string imports at compile time π This switch is required in order to useimport(file)expressions π Multiple-Joptions can be used, and the paths get searched in the same order π-Ldirβ when linking, a library search directory, same as with gcc π-Bdirβ where to find the compiler's own executables, libraries, source files, and data files, same as with gcc π-fmodule-file=module=specβ manipulates file paths of imported modules π€οΈ If an imported module matches all or the leftmost part ofmodule, then the file path inspecis used as the location to search for D sources π This is handy when the 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 in all import paths for the source file foo.d when importing A.B, and to search the directory bar/ when importing C, as annotated in this 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β usesdiras a subdirectory of the gcc directory containing target-specific D sources and interfaces π―-iprefix prefixβ specifiesprefixas the prefix for the gcc directory containing target-specific D sources and interfaces π§ If the prefix represents a directory, you should include the final'/'π-nostdincβ don't search the standard system directories for D source and interface files π Only the directories specified with-Ioptions (and the directory of the current file, if appropriate) get searched π
(continued in part 2 π)
-MDβ okay so this is basically-M -MF fileπ The driver figures out the file name by stripping any directory components and suffix off your input file, then tacking on a.depssuffix π§-MMDβ same energy as-MD, but it doesn't mention imported modules that come from the D standard library package directories π-Xβ dumps info about the contents of every source file being compiled, in JSON format, into a file π¦ The driver picks the name by removing directory components and suffix from the input file, then adding a.jsonsuffix πΈ-Xf fileβ same as-X, but all the JSON goes into the exact file you name π-fdocβ generates "Ddoc" documentation and writes it to a file β¨ The compiler names the file by stripping directory components and suffix from the input file, then adding a.htmlsuffix π-fdoc-dir=dirβ same as-fdoc, but the docs go into the directorydirποΈ You can pair it with-fdoc-file=fileto set the output file and directory path separately π¦-fdoc-file=fileβ same as-fdoc, but the docs go intofileπ It works with-fdoc-dir=dirso you can set the file and directory independently π-fdoc-inc=fileβ readsfileas a Ddoc macro file π You can use several-fdoc-incoptions, and the files get read and processed in the same order you gave them β
π¨ Warnings π¨
Warnings are diagnostic messages about constructions that aren't inherently erroneous but are risky, or that suggest there's probably a bug in the program. Unless -Werror is specified, they don't stop the 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 it's only checked for casting between an imaginary and non-imaginary data type, or between a D and C++ class π-Wno-deprecatedβ no warnings about usage of deprecated features and symbols with "deprecated" attributes π-Werrorβ turns all warnings into errors π₯-Wspeculativeβ lists all error messages from speculative compiles, like__traits(compiles, ...)π§ It doesn't report them as warnings, so they never become errors even when-Werroris also used π‘οΈ-Wtemplatesβ warns whenever a template instantiation is encountered π« Some coding rules disallow templates, so this can help enforce that rule π-Wunknown-pragmasβ warns when apragma()is encountered 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 atn, at which point gdc bails out instead of trying to keep going π Ifnis0(the default), there's no limit on how many errors 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 info on all language changescheckimportsβ gives deprecation messages about-ftransition=importanomaliescomplexβ lists all usages of complex or imaginary typesdip1000β implementshttp://wiki.dlang.org/DIP1000(experimental) π§ͺdip25β implementshttp://wiki.dlang.org/DIP25(experimental) π§ͺfieldβ lists all non-mutable fields which occupy an object instanceimportβ 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 π Protection ("private","package","protected") of symbols is also enforced to resolve conflicts between private and public symbols π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 bother with them otherwise π
-defaultlib libnameβ useslibnameinstead of libphobos when linking π Options that set the linkage of libphobos, like-static-libphobosor-shared-libphobos, get ignored π-debuglibβ 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 here too π-nophoboslibβ doesn't use the Phobos or D runtime library when linking π« Linkage options like-static-libphobosor-shared-libphobosare ignored π The standard system libraries are 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, 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 is all about 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-2019 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) π
Okay bestie, that's the whole GDC(1) page! π This one comes from the gcc-9 set and was last touched on 2022-05-27, so you're officially up to speed on your D compiler flags π
π¦ bye bestie π
π¦ where this page comes from
- ubuntu noble: gdc-9-powerpc-linux-gnu 9.5.0-6ubuntu2.1cross1
- ubuntu noble: gdc-9-powerpc-linux-gnu 9.5.0-6ubuntu2cross1
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms