1GDC(1)                                GNU                               GDC(1)
2
3
4

NAME

6       gdc - A GCC-based compiler for the D language
7

SYNOPSIS

9       gdc [-c|-S] [-g] [-pg]
10           [-Olevel] [-Wwarn...]
11           [-Idir...] [-Ldir...]
12           [-foption...] [-mmachine-option...]
13           [-o outfile] [@file] infile...
14
15       Only the most useful options are listed here; see below for the
16       remainder.
17

DESCRIPTION

19       The gdc command is the GNU compiler for the D language and supports
20       many of the same options as gcc.  This manual only documents the
21       options specific to gdc.
22

OPTIONS

24   Input and Output files
25       For any given input file, the file name suffix determines what kind of
26       compilation is done.  The following kinds of input file names are
27       supported:
28
29       file.d
30           D source files.
31
32       file.dd
33           Ddoc source files.
34
35       file.di
36           D interface files.
37
38       You can specify more than one input file on the gdc command line, each
39       being compiled separately in the compilation process.  If you specify a
40       "-o file" option, all the input files are compiled together, producing
41       a single output file, named file.  This is allowed even when using "-S"
42       or "-c".
43
44       A D interface file contains only what an import of the module needs,
45       rather than the whole implementation of that module.  They can be
46       created by gdc from a D source file by using the "-H" option.  When the
47       compiler resolves an import declaration, it searches for matching .di
48       files first, then for .d.
49
50       A Ddoc source file contains code in the D macro processor language.  It
51       is primarily designed for use in producing user documentation from
52       embedded comments, with a slight affinity towards HTML generation.  If
53       a .d source file starts with the string "Ddoc" then it is treated as
54       general purpose documentation, not as a D source file.
55
56   Runtime Options
57       These options affect the runtime behavior of programs compiled with
58       gdc.
59
60       -fall-instantiations
61           Generate code for all template instantiations.  The default
62           template emission strategy is to not generate code for declarations
63           that were either instantiated speculatively, such as from
64           "__traits(compiles, ...)", or that come from an imported module not
65           being compiled.
66
67       -fno-assert
68           Turn off code generation for "assert" contracts.
69
70       -fno-bounds-check
71           Turns off array bounds checking for all functions, which can
72           improve performance for code that uses arrays extensively.  Note
73           that this can result in unpredictable behavior if the code in
74           question actually does violate array bounds constraints.  It is
75           safe to use this option if you are sure that your code never throws
76           a "RangeError".
77
78       -fbounds-check=value
79           An alternative to -fbounds-check that allows more control as to
80           where bounds checking is turned on or off.  The following values
81           are supported:
82
83           on  Turns on array bounds checking for all functions.
84
85           safeonly
86               Turns on array bounds checking only for @safe functions.
87
88           off Turns off array bounds checking completely.
89
90       -fno-builtin
91           Don't recognize built-in functions unless they begin with the
92           prefix __builtin_.  By default, the compiler will recognize when a
93           function in the "core.stdc" package is a built-in function.
94
95       -fdebug
96       -fdebug=value
97           Turn on compilation of conditional "debug" code into the program.
98           The -fdebug option itself sets the debug level to 1, while -fdebug=
99           enables "debug" code that are identified by any of the following
100           values:
101
102           level
103               Sets the debug level to level, any "debug" code <= level is
104               compiled into the program.
105
106           ident
107               Turns on compilation of any "debug" code identified by ident.
108
109       -fno-druntime
110           Implements <https://dlang.org/spec/betterc.html>.  Assumes that
111           compilation targets an environment without a D runtime library.
112
113           This is equivalent to compiling with the following options:
114
115                   gdc -nophoboslib -fno-exceptions -fno-moduleinfo -fno-rtti
116
117       -fno-invariants
118           Turns off code generation for class "invariant" contracts.
119
120       -fno-moduleinfo
121           Turns off generation of the "ModuleInfo" and related functions that
122           would become unreferenced without it, which may allow linking to
123           programs not written in D.  Functions that are not be generated
124           include module constructors and destructors ("static this" and
125           "static ~this"), "unittest" code, and "DSO" registry functions for
126           dynamically linked code.
127
128       -fonly=filename
129           Tells the compiler to parse and run semantic analysis on all
130           modules on the command line, but only generate code for the module
131           specified by filename.
132
133       -fno-postconditions
134           Turns off code generation for postcondition "out" contracts.
135
136       -fno-preconditions
137           Turns off code generation for precondition "in" contracts.
138
139       -frelease
140           Turns on compiling in release mode, which means not emitting
141           runtime checks for contracts and asserts.  Array bounds checking is
142           not done for @system and @trusted functions, and assertion failures
143           are undefined behavior.
144
145           This is equivalent to compiling with the following options:
146
147                   gdc -fno-assert -fbounds-check=safe -fno-invariants \
148                       -fno-postconditions -fno-preconditions -fno-switch-errors
149
150       -fno-rtti
151           Turns off generation of run-time type information for all user
152           defined types.  Any code that uses features of the language that
153           require access to this information will result in an error.
154
155       -fno-switch-errors
156           This option controls what code is generated when no case is matched
157           in a "final switch" statement.  The default run time behavior is to
158           throw a "SwitchError".  Turning off -fswitch-errors means that
159           instead the execution of the program is immediately halted.
160
161       -funittest
162           Turns on compilation of "unittest" code, and turns on the
163           "version(unittest)" identifier.  This implies -fassert.
164
165       -fversion=value
166           Turns on compilation of conditional "version" code into the program
167           identified by any of the following values:
168
169           level
170               Sets the version level to level, any "version" code >= level is
171               compiled into the program.
172
173           ident
174               Turns on compilation of "version" code identified by ident.
175
176       -fno-weak
177           Turns off emission of instantiated declarations that can be defined
178           in multiple objects as weak or one-only symbols.  The default is to
179           emit all public symbols as weak, unless the target lacks support
180           for weak symbols.  Disabling this option means that common symbols
181           are instead put in COMDAT or become private.
182
183   Options for Directory Search
184       These options specify directories to search for files, libraries, and
185       other parts of the compiler:
186
187       -Idir
188           Specify a directory to use when searching for imported modules at
189           compile time.  Multiple -I options can be used, and the paths are
190           searched in the same order.
191
192       -Jdir
193           Specify a directory to use when searching for files in string
194           imports at compile time.  This switch is required in order to use
195           "import(file)" expressions.  Multiple -J options can be used, and
196           the paths are searched in the same order.
197
198       -Ldir
199           When linking, specify a library search directory, as with gcc.
200
201       -Bdir
202           This option specifies where to find the executables, libraries,
203           source files, and data files of the compiler itself, as with gcc.
204
205       -fmodule-file=module=spec
206           This option manipulates file paths of imported modules, such that
207           if an imported module matches all or the leftmost part of module,
208           the file path in spec is used as the location to search for D
209           sources.  This is used when the source file path and names are not
210           the same as the package and module hierarchy.  Consider the
211           following examples:
212
213                   gdc test.d -fmodule-file=A.B=foo.d -fmodule-file=C=bar
214
215           This will tell the compiler to search in all import paths for the
216           source file foo.d when importing A.B, and the directory bar/ when
217           importing C, as annotated in the following D code:
218
219                   module test;
220                   import A.B;     // Matches A.B, searches for foo.d
221                   import C.D.E;   // Matches C, searches for bar/D/E.d
222                   import A.B.C;   // No match, searches for A/B/C.d
223
224       -imultilib dir
225           Use dir as a subdirectory of the gcc directory containing target-
226           specific D sources and interfaces.
227
228       -iprefix prefix
229           Specify prefix as the prefix for the gcc directory containing
230           target-specific D sources and interfaces.  If the prefix represents
231           a directory, you should include the final '/'.
232
233       -nostdinc
234           Do not search the standard system directories for D source and
235           interface files.  Only the directories that have been specified
236           with -I options (and the directory of the current file, if
237           appropriate) are searched.
238
239   Code Generation
240       In addition to the many gcc options controlling code generation, gdc
241       has several options specific to itself.
242
243       -H  Generates D interface files for all modules being compiled.  The
244           compiler determines the output file based on the name of the input
245           file, removes any directory components and suffix, and applies the
246           .di suffix.
247
248       -Hd dir
249           Same as -H, but writes interface files to directory dir.  This
250           option can be used with -Hf file to independently set the output
251           file and directory path.
252
253       -Hf file
254           Same as -H but writes interface files to file.  This option can be
255           used with -Hd dir to independently set the output file and
256           directory path.
257
258       -M  Output the module dependencies of all source files being compiled
259           in a format suitable for make.  The compiler outputs one make rule
260           containing the object file name for that source file, a colon, and
261           the names of all imported files.
262
263       -MM Like -M but does not mention imported modules from the D standard
264           library package directories.
265
266       -MF file
267           When used with -M or -MM, specifies a file to write the
268           dependencies to.  When used with the driver options -MD or -MMD,
269           -MF overrides the default dependency output file.
270
271       -MG This option is for compatibility with gcc, and is ignored by the
272           compiler.
273
274       -MP Outputs a phony target for each dependency other than the modules
275           being compiled, causing each to depend on nothing.
276
277       -MT target
278           Change the target of the rule emitted by dependency generation to
279           be exactly the string you specify.  If you want multiple targets,
280           you can specify them as a single argument to -MT, or use multiple
281           -MT options.
282
283       -MQ target
284           Same as -MT, but it quotes any characters which are special to
285           make.
286
287       -MD This option is equivalent to -M -MF file.  The driver determines
288           file by removing any directory components and suffix from the input
289           file, and then adding a .deps suffix.
290
291       -MMD
292           Like -MD but does not mention imported modules from the D standard
293           library package directories.
294
295       -X  Output information describing the contents of all source files
296           being compiled in JSON format to a file.  The driver determines
297           file by removing any directory components and suffix from the input
298           file, and then adding a .json suffix.
299
300       -Xf file
301           Same as -X, but writes all JSON contents to the specified file.
302
303       -fdoc
304           Generates "Ddoc" documentation and writes it to a file.  The
305           compiler determines file by removing any directory components and
306           suffix from the input file, and then adding a .html suffix.
307
308       -fdoc-dir=dir
309           Same as -fdoc, but writes documentation to directory dir.  This
310           option can be used with -fdoc-file=file to independently set the
311           output file and directory path.
312
313       -fdoc-file=file
314           Same as -fdoc, but writes documentation to file.  This option can
315           be used with -fdoc-dir=dir to independently set the output file and
316           directory path.
317
318       -fdoc-inc=file
319           Specify file as a Ddoc macro file to be read.  Multiple -fdoc-inc
320           options can be used, and files are read and processed in the same
321           order.
322
323   Warnings
324       Warnings are diagnostic messages that report constructions that are not
325       inherently erroneous but that are risky or suggest there is likely to
326       be a bug in the program.  Unless -Werror is specified, they do not
327       prevent compilation of the program.
328
329       -Wall
330           Turns on all warnings messages.  Warnings are not a defined part of
331           the D language, and all constructs for which this may generate a
332           warning message are valid code.
333
334       -Walloca
335           This option warns on all uses of "alloca" in the source.
336
337       -Walloca-larger-than=n
338           Warn on unbounded uses of alloca, and on bounded uses of alloca
339           whose bound can be larger than n bytes.  -Wno-alloca-larger-than
340           disables -Walloca-larger-than warning and is equivalent to
341           -Walloca-larger-than=SIZE_MAX or larger.
342
343       -Wcast-result
344           Warn about casts that will produce a null or zero result.
345           Currently this is only done for casting between an imaginary and
346           non-imaginary data type, or casting between a D and C++ class.
347
348       -Wno-deprecated
349           Do not warn about usage of deprecated features and symbols with
350           "deprecated" attributes.
351
352       -Werror
353           Turns all warnings into errors.
354
355       -Wspeculative
356           List all error messages from speculative compiles, such as
357           "__traits(compiles, ...)".  This option does not report messages as
358           warnings, and these messages therefore never become errors when the
359           -Werror option is also used.
360
361       -Wtemplates
362           Warn when a template instantiation is encountered.  Some coding
363           rules disallow templates, and this may be used to enforce that
364           rule.
365
366       -Wunknown-pragmas
367           Warn when a "pragma()" is encountered that is not understood by
368           gdc.  This differs from -fignore-unknown-pragmas where a pragma
369           that is part of the D language, but not implemented by the
370           compiler, won't get reported.
371
372       -fignore-unknown-pragmas
373           Turns off errors for unsupported pragmas.
374
375       -fmax-errors=n
376           Limits the maximum number of error messages to n, at which point
377           gdc bails out rather than attempting to continue processing the
378           source code.  If n is 0 (the default), there is no limit on the
379           number of error messages produced.
380
381       -fsyntax-only
382           Check the code for syntax errors, but do not actually compile it.
383           This can be used in conjunction with -fdoc or -H to generate files
384           for each module present on the command-line, but no other output
385           file.
386
387       -ftransition=id
388           Report additional information about D language changes identified
389           by id.  The following values are supported:
390
391           all List information on all language changes.
392
393           checkimports
394               Give deprecation messages about -ftransition=import anomalies.
395
396           complex
397               List all usages of complex or imaginary types.
398
399           dip1000
400               Implements <http://wiki.dlang.org/DIP1000> (experimental).
401
402           dip25
403               Implements <http://wiki.dlang.org/DIP25> (experimental).
404
405           field
406               List all non-mutable fields which occupy an object instance.
407
408           import
409               Tells the compiler to revert to using an old lookup behavior
410               for resolving unqualified symbol names, where this was done in
411               a single pass, ignoring any protection attributes.  The default
412               name lookup strategy is to use two passes, the first ignoring
413               imported declarations, and the second only looking at imports.
414               The protection ("private", "package", "protected") of symbols
415               is also enforced to resolve any conflicts between private and
416               public symbols.
417
418           nogc
419               List all hidden GC allocations.
420
421           tls List all variables going into thread local storage.
422
423   Options for Linking
424       These options come into play when the compiler links object files into
425       an executable output file.  They are meaningless if the compiler is not
426       doing a link step.
427
428       -defaultlib libname
429           Specify the library to use instead of libphobos when linking.
430           Options specifying the linkage of libphobos, such as
431           -static-libphobos or -shared-libphobos, are ignored.
432
433       -debuglib
434           Specify the debug library to use instead of libphobos when linking.
435           This option has no effect unless the -g option was also given on
436           the command line.  Options specifying the linkage of libphobos,
437           such as -static-libphobos or -shared-libphobos, are ignored.
438
439       -nophoboslib
440           Do not use the Phobos or D runtime library when linking.  Options
441           specifying the linkage of libphobos, such as -static-libphobos or
442           -shared-libphobos, are ignored.  The standard system libraries are
443           used normally, unless -nostdlib or -nodefaultlibs is used.
444
445       -shared-libphobos
446           On systems that provide libgphobos and libgdruntime as a shared and
447           a static library, this option forces the use of the shared version.
448           If no shared version was built when the compiler was configured,
449           this option has no effect.
450
451       -static-libphobos
452           On systems that provide libgphobos and libgdruntime as a shared and
453           a static library, this option forces the use of the static version.
454           If no static version was built when the compiler was configured,
455           this option has no effect.
456
457   Developer Options
458       This section describes command-line options that are primarily of
459       interest to developers or language tooling.
460
461       -fdump-d-original
462           Output the internal front-end AST after the "semantic3" stage.
463           This option is only useful for debugging the GNU D compiler itself.
464
465       -v  Dump information about the compiler language processing stages as
466           the source program is being compiled.  This includes listing all
467           modules that are processed through the "parse", "semantic",
468           "semantic2", and "semantic3" stages; all "import" modules and their
469           file paths; and all "function" bodies that are being compiled.
470

SEE ALSO

472       gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entries for gdc
473       and gcc.
474
476       Copyright (c) 2006-2019 Free Software Foundation, Inc.
477
478       Permission is granted to copy, distribute and/or modify this document
479       under the terms of the GNU Free Documentation License, Version 1.3 or
480       any later version published by the Free Software Foundation; with no
481       Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.  A
482       copy of the license is included in the man page gfdl(7).
483
484
485
486gcc-9                             2019-05-03                            GDC(1)
Impressum