GDC(1)
π GDC(1): the GNU D compiler manual (part 1 of 2) π
β¨ NAME β¨
gdc is 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...
okay so the synopsis only flashes the most useful options π the rest are down below, bestie π
β¨ DESCRIPTION β¨
The gdc command is the GNU compiler for the D language, and it supports a lot of the same options as gcc π₯ This page only covers the options that are specific to gdc, so that's where the focus is π
β¨ OPTIONS β¨
π Input and Output files π
okay so the file name suffix decides what kind of compilation happens π these are the input file name kinds that work:
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 in the process π but if you use -o file, all the input files get compiled together into one single output file named file π«Ά that works even with -S or -c, periodt π
a D interface file only holds what an import of the module actually needs, not the whole implementation of that module π¦ you can make these from a D source file with the -H option. when the compiler resolves an import declaration, it looks for matching .di files first, and then for .d files π
a Ddoc source file holds 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 πΈ and if a .d source file starts with the string Ddoc, it gets treated as general purpose documentation instead of D source π
π Runtime Options π
these options change how programs compiled with gdc behave at runtime β‘
-fall-instantiationsβ generates code for all template instantiations π§ the default emission strategy is different though: it skips code for declarations that were either 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 give your performance a boost for code that uses arrays a lot ποΈ it's safe to use this only if you're sure your code never throws aRangeErrorπ«Ά
π Heads up: if the code in question actually does violate array bounds constraints, this can result in unpredictable behavior.
-fbounds-check=valueβ an alternative to-fbounds-checkthat gives you more control over where bounds checking gets turned on or off ποΈ the supported values are: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 start with the prefix__builtin_π by default, the compiler does recognize when a function in thecore.stdcpackage is a built-in function β¨-fdebug,-fdebug=valueβ turns on compilation of conditionaldebugcode into your 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 tolevel, so anydebugcode<= levelgets compiled in.identβ turns on compilation of anydebugcode identified byident.
-fno-druntimeβ implements the spec athttps://dlang.org/spec/betterc.htmlπ it assumes you're compiling for an environment with no D runtime library ποΈ this is basically the same as 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 of theModuleInfoand related functions that would become unreferenced without it, which may allow linking to programs not written in D π the functions that don't get 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, and assertion failures are undefined behavior. this is basically the same as compiling with these options π
π Heads up: under -frelease, assertion failures are undefined behavior.
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 runtime behavior is to throw aSwitchError. turning off-fswitch-errorsmeans the program's execution 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 put inCOMDATinstead, or become private π
π Options for Directory Search π
these options tell gdc where to look for files, libraries, and other parts of the compiler ποΈ
-Idirβ specify a directory to search when looking for imported modules at compile time π¦ you can use multiple-Ioptions, and the paths are searched in the same order.-Jdirβ specify a directory to search when looking for files in string imports at compile time π this switch is required if you want to useimport(file)expressions. you can use multiple-Joptions, and the paths are searched in the same order.-Ldirβ when linking, specify a library search directory, as withgccπ-Bdirβ specifies where to find the executables, libraries, source files, and data files of the compiler itself, as withgccπ οΈ-fmodule-file=module=specβ a little spicy πΆοΈ but super useful. it manipulates file paths of imported modules, so that if an imported module matches all or the leftmost part ofmodule, the file path inspecis used as the location to search for D sources. you'd use this 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 all import paths for the source file foo.d when importing A.B, and the directory bar/ when importing C, as annotated in the D code below:
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 thegccdirectory that contains target-specific D sources and interfaces π―-iprefix prefixβ specifiesprefixas the prefix for thegccdirectory that contains 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 -MF filein a cute little disguise π§₯ The driver figures outfileby chopping off any directory bits and the suffix from the input file, then slapping a.depssuffix on the end. π-MMDβ Same vibe as-MD, but it doesn't mention imported modules 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 names that file by removing any directory components and suffix from the input file, then adding a.jsonsuffix. Literally so organized π-Xf fileβ Same energy as-X, except all the JSON goes into the specific file you pick β¨-fdocβ Generates "Ddoc" documentation and writes it to a file. The compiler names the file by removing 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. Main character energy π-fdoc-file=fileβ Same as-fdoc, but the docs go intofile. Use it with-fdoc-dir=dirif you want to set the file and directory independently π¦-fdoc-inc=fileβ Tells it to readfileas 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 β¨
Okay bestie, warnings are diagnostic messages about constructions that aren't straight-up wrong but are risky, or that hint there's probably a bug hiding in the program. Unless you add -Werror, they won't stop your program from compiling π«Ά
-Wallβ Turns on all warning messages. Warnings aren't an official part of the D language, and every construct that might 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 thannbytes.-Wno-alloca-larger-thanturns off the-Walloca-larger-thanwarning, and it's the same as-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 non-imaginary data type, or between a D and C++ class π§-Wno-deprecatedβ Don't warn about deprecated features and symbols that have "deprecated" attributes π-Werrorβ Turns every warning into an error. Serious, no cap π₯-Wspeculativeβ Lists all error messages from speculative compiles, like__traits(compiles, ...). This option doesn't report the messages as warnings, so they never become errors, even when-Werroris also in use π¦-Wtemplatesβ Warns whenever a template instantiation is encountered. Some coding rules ban templates, and this can help you enforce that rule π-Wunknown-pragmasβ Warns whenpragma()shows up and gdc doesn't understand it. This is different from-fignore-unknown-pragmas, because a pragma that's part of the D language but isn't implemented by the compiler won't get reported with this one π-fignore-unknown-pragmasβ Turns off errors for unsupported pragmas β¨-fmax-errors=nβ Caps the number of error messages atn. Once it hits that number, gdc bails out instead of trying to keep going through the source code. Ifnis 0 (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 doesn't produce any other output file π-ftransition=idβ Reports extra info about D language changes identified byid. The supported values are:allβ Lists info on all language changes.checkimportsβ Gives deprecation messages about-ftransition=importanomalies.complexβ Lists all usages of complex or imaginary types.dip1000β Implementshttps://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md(Scoped pointers) π₯dip25β Implementshttps://github.com/dlang/DIPs/blob/master/DIPs/archive/DIP25.md(Sealed references) πfieldβ Lists all non-mutable fields that occupy an object instance.importβ Tells the compiler to go back to an old lookup behavior for resolving unqualified symbol names, where that lookup was done in a single pass and ignored any protection attributes. The default name lookup strategy uses two passes instead: 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 only matter when the compiler links object files into an executable output file. If the compiler isn't doing a link step, they're meaningless, so don't stress π¦
-defaultlib=libnameβ 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=libnameβ Specifies the debug library to use instead of libphobos when linking. This does nothing unless-gwas also given on the command line. Options that set the linkage of libphobos, like-static-libphobosor-shared-libphobos, get ignored too πΈ-nophoboslibβ Don'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 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, this 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, this does nothing π§
β¨ Developer Options β¨
This section is for the command-line options that mostly matter to developers or language tooling. Main developer hours π€π
-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. Go read those when you want the full story, bestie ππ
β¨ COPYRIGHT β¨
Copyright (c) 2006-2020 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 on GDC(1), bestie π This one is from the gcc-10 source, dated 2023-07-07, and you absolutely slayed reading the whole thing π
β¨
π¦ where this page comes from
- ubuntu noble: gdc-10-mipsisa32r6-linux-gnu 10.5.0-4ubuntu2cross1
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms