GDC(1)
πΈ NAME πΈ
gdc β a GCC-based compiler for the D language β¨ straight outta the GNU manual, page GDC(1), and bestie it's so much. π
β¨ SYNOPSIS β¨
gdc [-c|-S] [-g] [-pg]
[-Olevel] [-Wwarn...]
[-Idir...] [-Ldir...]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
okay so real talk β only the most useful options are listed up here π, the rest are down below, keep scrolling, no skipping π
π« 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 β so like, the D-specific stuff, the gcc lore lives somewhere else, iykyk π«Ά
π₯ OPTIONS π₯
π Input and Output files π
For any given input file, the file name suffix decides what kind of compilation is gonna happen. These are the input file name kinds that are supported, and honestly? they ate π
file.dβ D source files πΈfile.ddβ Ddoc source files πfile.diβ D interface files π¦
You can specify more than one input file on the gdc command line, and each one gets compiled separately in the compilation process. Now if you specify a -o file option, 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 β yes, even then π
A D interface file contains only what an import of the module needs, rather than the whole 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. first come first served, periodt β¨
A Ddoc source file contains code in the D macro processor language. It is 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 is treated as general purpose documentation, not as a D source file. main character behavior fr fr.
β‘ Runtime Options β‘
These options affect the runtime behavior of programs compiled with gdc. pay attention bestie, this is the good part π
-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, such as from__traits(compiles, ...), or that come from an imported module not being compiled. π-fno-assertβ Turn off code generation forassertcontracts. 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 aRangeError.
β οΈ okay so read this part twice β unpredictable behavior is a real thing here. only reach for it if you're sure nothing ever throws a RangeError, no cap.
-fbounds-check=valueβ An alternative to-fbounds-checkthat 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@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 will recognize when a function in thecore.stdcpackage 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 anAssertErrorwith extra context information. πhaltβ Halt the program execution. πthrowβ Throw anAssertError(the default). π―
-fdebug,-fdebug=valueβ Turn on compilation of conditionaldebugcode into the program. The-fdebugoption itself sets the debug level to 1, while-fdebug=enablesdebugcode that are identified by any of the following values:levelβ Sets the debug level to level, anydebugcode<= levelis compiled into the program.identβ Turns on compilation of anydebugcode 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 classinvariantcontracts. π«-fmainβ Generates a defaultmain()function when compiling. This is useful when unittesting a library, as it enables running the unittests in a library without having to manually define an entry-point function. This option does nothing whenmainis already defined in user code. cute lil shortcut π-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. Functions that are not 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 by filename. π―-fno-postconditionsβ Turns off code generation for postconditionoutcontracts. πͺ-fno-preconditionsβ Turns off code generation for preconditionincontracts. πͺ-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. π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 foralias thisbefore searching in upper scopes.inβ Implementsinparameters to meanscope const [ref]and accepts rvalues.inclusiveincontractsβ Implementsincontracts of overridden methods to be a superset of parent contract.intpromoteβ Implements C-style integral promotion for unary+,-and~expressions.nosharedaccessβ Turns off and disallows all access to shared memory objects.rvaluerefparamβ Implements rvalue arguments torefparameters.shortenedmethodsβ Implements use of=>for methods and top-level functions in addition to lambdas.
-freleaseβ Turns on compiling in release mode, which means not emitting runtime checks for contracts and asserts. Array bounds checking is not done for@systemand@trustedfunctions, and assertion failures are undefined behavior.
β οΈ yes bestie, undefined behavior β that's the dramatic kind. it means exactly what it says. π
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:allβ Turns off all revertable D language features. β©οΈdip25β Reverts https://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md (Sealed references).dtorfieldsβ Turns off generation for destructing fields of partially constructed objects.markdownβ Turns off Markdown replacements in Ddoc comments.
-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 afinal switchstatement. The default run time behavior is to throw aSwitchError. Turning off-fswitch-errorsmeans that instead the execution of the program is immediately halted. π-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 the following values:levelβ Sets the version level to level, anyversioncode>= levelis compiled into the program.identβ Turns on compilation ofversioncode 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.
π Options for Directory Search π
These options specify directories to search for files, libraries, and other parts of the compiler:
-Idirβ Specify a directory to use when searching for imported modules at compile time. Multiple-Ioptions can be used, and the paths are searched in the same order. ποΈ
okay and that's where this part wraps, bestie β but we are not done, keep going, there's more coming π β¨
-Jdirβ okay so bestie, this tells the compiler where to look for files when it's doing string imports at compile time. You need this switch if you wanna useimport(file)expressions. You can stack multiple-Joptions, and the paths get searched in the same order. π-Ldirβ when you're linking, this says βhey, look in this directory for libraries,β just likegccdoes. π«Ά-Bdirβ this one points to where the compiler's own executables, libraries, source files, and data files live, same vibe asgcc. β¨-fmodule-file=module=specβ okay so this 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. It's used when the source file path and names are not the same as the package and module hierarchy. Consider this example:
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 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β usediras a subdirectory of thegccdirectory that holds target-specific D sources and interfaces. π-iprefix prefixβ setsprefixas the prefix for thegccdirectory with target-specific D sources and interfaces. If the prefix is a directory, bestie, include that final/. π-nostdincβ do not search the standard system directories for D source and interface files. Only the directories you gave with-Ioptions (and the directory of the current file, if appropriate) get searched. periodt. πΈ
β¨ Code Generation β¨
Besides all the gcc options that control code generation, gdc has its own little set of options. slay. π
-Hβ generates D interface files for every module being compiled. The compiler figures out the output file from the input file's name, strips any directory components and suffix, then slaps on a.disuffix. iconic. β¨-Hd dirβ same as-H, but writes interface files into directorydir. You can pair it with-Hf fileto set the output file and directory path independently. π«Ά-Hf fileβ same as-Hbut writes interface files tofile. You can use it with-Hd dirto independently set the output file and directory path. π-Mβ spits out the module dependencies of all source files being compiled in a format thatmakecan eat. The compiler outputs onemakerule with the object file name for that source file, a colon, and the names of all imported files. π₯-MMβ like-M, but it doesn't mention imported modules from the D standard library package directories. π-MF fileβ when you use it with-Mor-MM, it says which file to write the dependencies to. When you use it with the driver options-MDor-MMD,-MFoverrides the default dependency output file. π-MGβ this is just for compatibility withgcc; the compiler ignores it. lowkey useless but there. π-MPβ outputs a phony target for each dependency other than the modules being compiled, so each one depends on nothing. π-MT targetβ changes the target of the rule emitted by dependency generation to be exactly the string you specify. Want multiple targets? You can pass them as a single argument to-MT, or use multiple-MToptions. slay. π-MQ targetβ same as-MT, but it quotes any characters that are special tomake. π§-MDβ equivalent to-M -MF file. The driver determinesfileby removing any directory components and suffix from the input file, then adding a.depssuffix. β¨-MMDβ like-MDbut 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 determinesfileby removing any 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 specifiedfile. π«Ά-fdocβ generates βDdocβ documentation and writes it to a file. The compiler determinesfileby removing any directory components and suffix from the input file, then adding a.htmlsuffix. π-fdoc-dir=dirβ same as-fdoc, but writes documentation to directorydir. You can use it with-fdoc-file=fileto independently set the output file and directory path. πΈ-fdoc-file=fileβ same as-fdoc, but writes documentation tofile. You can use it with-fdoc-dir=dirto independently set the output file and directory path. π-fdoc-inc=fileβ specifyfileas a Ddoc macro file to read. You can use multiple-fdoc-incoptions, and files are read and processed in the same order. π-fdump-c++-spec=fileβ for D source files, generate corresponding C++ declarations infile. β¨-fdump-c++-spec-verboseβ use it with-fdump-c++-spec=above, and 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 tofile. It's useful for debugging compilation errors and gives debuggers source to show when requested. π
β οΈ Warnings β οΈ
Warnings are diagnostic messages that call out constructions that aren't inherently erroneous but are risky or suggest there's probably a bug in the program. Unless -Werror is specified, they do not prevent compilation. so dramatic but also fair. π
-Wallβ turns on all warnings messages. Warnings aren't a defined part of the D language, and every construct that might trigger one is still valid code. periodt. π₯-Wallocaβ warns on every use 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 the-Walloca-larger-thanwarning and 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 is only done for casting between an imaginary and non-imaginary data type, or casting between a D and C++ class. π-Wno-deprecatedβ do not warn about usage of deprecated features and symbols with βdeprecatedβ attributes. π-Werrorβ turns all warnings into errors. no mercy. π€-Wspeculativeβ lists all error messages from speculative compiles, like__traits(compiles, ...). This option doesn't report messages as warnings, so these messages never become errors even when-Werroris also used. π§-Wtemplatesβ warns when a template instantiation is encountered. Some coding rules disallow templates, and this can enforce that rule. π-Wunknown-pragmasβ warns when apragma()is encountered thatgdcdoesn't understand. 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β do not warn upon questionable usage of the macros used to handle variable arguments likeva_start. π-fignore-unknown-pragmasβ turns off errors for unsupported pragmas. π-fmax-errors=nβ limits the maximum number of error messages ton, and at that pointgdcbails out instead of trying to continue processing the source code. Ifnis0(the default), there's no limit on the number of error messages 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 present on the command-line, but no other output file. β¨-ftransition=idβ reports additional info about D language changes identified byid. 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.vmarkdownβ List instances of Markdown replacements in Ddoc.
π 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. so don't bother otherwise. π
-defaultlib=libnameβ specifies the library to use instead oflibphoboswhen linking. Options that specify the linkage oflibphobos, like-static-libphobosor-shared-libphobos, are ignored. π«Ά-debuglib=libnameβ specifies the debug library to use instead oflibphoboswhen linking. This has no effect unless-gwas also given on the command line. Options specifying the linkage oflibphobos, like-static-libphobosor-shared-libphobos, are ignored. π-nophoboslibβ do not use the Phobos or D runtime library when linking. Options specifying the linkage oflibphobos, like-static-libphobosor-shared-libphobos, are ignored. The standard system libraries are used normally, unless-nostdlibor-nodefaultlibsis used. π-shared-libphobosβ on systems that providelibgphobosandlibgdruntimeas 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 has no effect. π§-static-libphobosβ on systems that providelibgphobosandlibgdruntimeas 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 has no effect. π
π οΈ Developer Options π οΈ
This section is for command-line options that are mainly interesting to developers or language tooling. iykyk. π
-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β okay bestie this one is chef's kiss for snooping on your own build π it dumps info about the compiler's language processing stages while your source program is being compiled. So like, live commentary but make it compiler. What does it show you? All of it:- every module getting processed through the
"parse","semantic","semantic2", and"semantic3"stages - every
"import"module and its file path ποΈ - every
"function"body that's currently being compiled
- every module getting processed through the
Basically a backstage pass to the whole pipeline. No cap, it's giving production diary. π¬
π¦ SEE ALSO π¦
Go read these when you're done here, they're the extended universe:
gpl(7)gfdl(7)fsf-funding(7)gcc(1)- and the Info entries for
gdcandgccπ
π COPYRIGHT π
Copyright (c) 2006-2022 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).
TL;DR bestie: yes you can copy it, share it, remix it β just keep it under the GFDL terms above and don't come for the Invariant Sections, because there aren't any. π«Ά
And that's the whole page, babes!! β¨ This one shipped as gcc-12, dated 2024-07-11, and it's filed under GDC(1) in the manual. Slay, go compile something iconic. π
ππ¦
π¦ where this page comes from
- ubuntu noble: gdc-12-mips64-linux-gnuabi64 12.4.0-2ubuntu1~24.04cross8
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms