GDC(1)
π GDC(1) β GNU manual, part 1 of 2 π
β¨ NAME β¨
okay so gdc is a GCC-based compiler for the D language π¦ that's the whole name, no cap.
β¨ SYNOPSIS β¨
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
Bestie, this is just the highlight reel π¬ Only the most useful options are up here, and the rest are down below.
β¨ DESCRIPTION β¨
The gdc command is the GNU compiler for the D language, and it's giving gcc energy because it supports a lot of the same options as gcc. This manual only covers the options that are specific to gdc, so we're skipping the gcc ones π
β¨ OPTIONS β¨
β¨ Input and Output files β¨
For any input file, the file name suffix decides what kind of compilation happens. These are the 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, and each one gets compiled separately during the process. But if you use -o file, all the input files get compiled together into one output file named file. That works even with -S or -c, so no skipping the rules π«Ά
A D interface file only has what an import of the module actually needs, not the whole implementation of that module. gdc can make them 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, then for .d files.
A Ddoc source file contains code in the D macro processor language. It's mainly for making user docs out of embedded comments, with a slight vibe toward HTML generation. If a .d source file starts with the string Ddoc, it's treated as general purpose documentation instead of a D source file π
β¨ Runtime Options β¨
These options affect how programs compiled with gdc behave at runtime πΈ
-fall-instantiationsβ Generates code for all template instantiations. The default strategy 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 improve performance for code that uses arrays a ton.
π¨ Heads up: if the code in question actually violates array bounds constraints, 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β A more flexible alternative to-fbounds-checkthat lets you pick where bounds checking gets 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β Doesn'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 of conditionaldebugcode into the program. The-fdebugoption by itself sets the debug level to 1, while-fdebug=enablesdebugcode identified by any of these values:- level β Sets the debug level to level, so any
debugcode<= levelgets compiled into the program. - ident β Turns on compiling of any
debugcode identified by ident.
- level β Sets the debug level to level, so any
-fno-druntimeβ Implementshttps://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
-fno-invariantsβ Turns off code generation for classinvariantcontracts.-fno-moduleinfoβ Turns off generation of theModuleInfoand related functions that would become unreferenced without it, which may allow linking to programs not written in D. The functions that won't be 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.
π Heads up: in this mode, 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
-fno-rttiβ Turns off generation of run-time type information for all user defined types. Any code that uses language features requiring access to this information 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 that the execution of the program is immediately halted instead.-funittestβ Turns on compiling ofunittestcode and turns on theversion(unittest)identifier. This implies-fassert.-fversion=valueβ Turns on compiling of conditionalversioncode into the program, identified by any of these values:- level β Sets the version level to level, so any
versioncode>= levelgets compiled into the program. - ident β Turns on compiling of
versioncode identified by ident.
- level β Sets the version level to level, so any
-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 that common symbols are instead put inCOMDATor become private.
β¨ Options for Directory Search β¨
These options specify which directories to search for files, libraries, and other parts of the compiler ποΈ
-Idirβ Specifies a directory to use when searching for imported modules at compile time. You can use multiple-Ioptions, and the paths get searched in the same order.-Jdirβ Specifies a directory to use when searching for files in string imports at compile time. This switch is required in order to useimport(file)expressions. You can use multiple-Joptions, and the paths get searched in the same order.-Ldirβ When linking, specifies a library search directory, just like with gcc.-Bdirβ Specifies where to find the executables, libraries, source files, and data files of the compiler itself, just like with gcc.-fmodule-file=module=specβ Manipulates file paths of imported modules. If an imported module matches all or the leftmost part ofmodule, the file path inspecis used as the location to search for D sources. This comes in clutch 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 the directory bar/ when importing C, as annotated in the following 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β Doesn'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.-MDβ β¨ okay so this one is basically-M -MFfile π The driver works out the file by stripping off any directory components and the suffix from the input file, then tacking on a.depssuffix. π-MMDβ Like-MD, but it doesn't mention imported modules from the D standard library package directories πΈ-Xβ Dumps info about the contents of all the source files being compiled, in JSON format, into a file π§ The driver picks the file name by stripping directory components and the suffix from the input file, then adding a.jsonsuffix. π¦-Xffile β Same vibe as-X, except all the JSON goes into the file you specify π-fdocβ Generates "Ddoc" documentation and writes it to a file π The compiler figures out the file name by stripping 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 directory dir. You can pair this with-fdoc-file=file to set the output file and the directory path separately π-fdoc-file=file β Same as-fdoc, but the docs go into file. Pair it with-fdoc-dir=dir to set the file and directory path independently β¨-fdoc-inc=file β Tells the compiler to read file as a Ddoc macro file. You can use multiple-fdoc-incoptions, and the files get read and processed in the same order you list them π
β οΈ Warnings β οΈ
Warnings are diagnostic messages that flag constructions which aren't inherently erroneous, but are risky or suggest there's probably a bug in the program π Unless you use -Werror, 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 here 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 of alloca whose bound could be larger than n bytes.-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 a non-imaginary data type, or between a D and C++ class π§-Wno-deprecatedβ Stops the warnings about using deprecated features and symbols that have "deprecated" attributes π-Werrorβ Turns all warnings into errors. No cap, it's a whole vibe check π«-Wspeculativeβ Lists all the error messages from speculative compiles, like__traits(compiles, ...). This option doesn't report messages as warnings, so they never become errors, even when-Werroris also used π§-Wtemplatesβ Warns whenever a template instantiation is encountered. Some coding rules ban templates, and this can help you 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 isn't implemented by the compiler won't get reported π-fignore-unknown-pragmasβ Turns off errors for unsupported pragmas πΈ-fmax-errors=n β Caps the maximum number of error messages at n. When you hit that number, gdc bails out instead of trying to keep processing the source code π If n is0(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 combine it with-fdocor-Hto generate files for each module on the command line, but it won't produce any other output file π-ftransition=id β Reports extra info about D language changes identified by id. These values are supported:allβ Lists info on all language changes πcheckimportsβ Gives deprecation messages about-ftransition=importanomalies π§complexβ Lists all usages of complex or imaginary types π«dip1000β Implements<http://wiki.dlang.org/DIP1000>(experimental) π§ͺdip25β Implements<http://wiki.dlang.org/DIP25>(experimental) π§ͺfieldβ Lists all non-mutable fields that occupy an object instance πimportβ Tells the compiler to go back to the old lookup behavior for resolving unqualified symbol names. That old way 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. The protection ("private","package","protected") of symbols is also enforced, so conflicts between private and public symbols get resolved π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.
Heads up bestie: if there's no link step, these options do absolutely nothing π
-defaultliblibname β 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β Specifies the debug library to use instead of libphobos when linking. This option 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β Doesn'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 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 use of the shared version. If no shared version was built when the compiler was configured, this option does nothing π-static-libphobosβ On systems that provide libgphobos and libgdruntime as both 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 does nothing π§±
π οΈ Developer Options π οΈ
This section covers command-line options that are mainly of interest to 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 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-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. 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) π
That's a wrap, bestie! π This page was written for gcc 9 and dated May 27, 2022. Now go read some D code and be iconic about it β¨π«Άπ
π¦ where this page comes from
- ubuntu jammy: gdc-9-hppa-linux-gnu 9.5.0-1ubuntu1~22.04cross1
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms