UserDocumentation

User Documentation

Usage of GDC.

Table of Contents:

Usage

Simple Compilation

Creating an executable is quite easy.

gdc main.d -o main

This will attempt to compile and link the file 'main.d' and place the output into the file 'main'. If you do not use the -o switch, then your executable will be called 'a.out'.

On a typical Unix system, you can execute the resulting program with "./main" or "./a.out". On Windows, you can run the program with "main" or "a.out".(?)

To help make a transition from DMD to GDC easier, there is a script called 'gdmd' which maps DMD's command line options to GDC. To see the available options for gdmd, type 'gdmd' or 'gdmd -help' on the command line.


Command line switches

A list of the available command line switches in GDC:

SwitchDescription
-I<dir>Add <dir> to the end of the main include path.
-J<dir>Add <dir> to the end of the string import path.
-fdeprecatedAllow use of deprecated features.
-fassertGenerate runtime code for assert()'s
-freleaseCompile release version
-f[no-]bounds-checkControls array bounds checking
-funittestCompile in unittest code
-fversion=<level/ident>Compile in version code >= <level> or identified by <ident>
-fdebug,-fdebug=<level>,-fdebug=<ident>Compile in debug code, code <= level, or code identified by ident
-fdebugCompile in debug code
-fdebug-cWith -g, generate C debug information for debugger compatibility
-fdeps=<filename>Write module dependencies to filename
-fd-verbosePrint information about D language processing to stdout
-fd-version=1Compile as D language version 1
-femit-templates=normal/private/all/none/auto
-f[no-]emit-templates
Controls whether or not template code is emitted.

"normal" -- Emit templates, expecting multiple copies to be merged by the linker.
"private" -- Emit templates, but make them private to the translation unit. The executable will have multiple copies of code and data.
"all" -- Emit all template instances with public visibility. Do this even if they would not normally be emitted.
"none" -- Do not emit templates at all.
"auto" -- For targets that support templates, the "full" mode is used. Otherwise, the "private" mode is used.

"none" and -fno-emit-templates are synonyms.
"auto" and -femit-templates are synonyms.
-fall-sourcesFor each source file on the command line, semantically process each file preceding it. Use this if compilation errors occur due to complicated circular module references. This will slow compilation noticeably
-nostdincDo not search standard system include directories
-fonly=Process all modules specified on the command line, but only generate code for the module specified by the argument.
-fod=<directory>Specify the object output directory. Note: this is actually a driver option; the backend ignores it.
-fopSpecify that the source file's parent directories should be appended to the object output directory. Note: this is actually a driver option; the backend ignores it.
-fignore-unknown-pragmasIgnore unsupported pragmas
-fintfcGenerate D interface files
-fintfc-dir=<dir>Write D interface files to directory <dir>
-fintfc-file=<filename>Write D interface file to <filename>
-fdocGenerate documentation
-fdoc-dir=<docdir>Write documentation file to docdir directory
-fdoc-file=<filename>Write documentation file to filename
-fdoc-inc=<filename>Include a Ddoc macro file
-fmultilib-dir=<dir>Select header multilib subdirectory
-Wsign-compareWarn about signed-unsigned comparisons
-fdump-sourceDump decoded UTF-8 text and source from HTML to <source>.utf-8 and <source>.d.utf-8
-fbuiltinRecognize built-in functions
-funsigned-charMake "char" unsigned by default (silently ignored in D)
-fsigned-charMake "char" signed by default (silently ignored in D)
-iprefix <path>Specify <path> as a prefix for next two options
-isysroot <dir>Set <dir> to be the system root directory
-isystem <dir>Add <dir> to the start of the system include path
-WallEnable most warning messages
-WerrorError out the compiler on warnings

Many of the options in GCC may also be applicable to GDC, such as optimization flags, -O1, -O2, -Os, -O3, or flags such as -c, which compiles a file, but does not link it, and will send the object file to "main.o", if you file is main.d


Extensions

Extended Assembler

GDC implements a GCC extension that allows inline assembler with D expression operands. It is available on nearly all targets, not just i386. The syntax differs from the C language extension in the follow ways. Statements start with 'asm { ...', just like the regular DMD inline assembler. It is not necesary to put parentheses around operands. Instruction templates can be compile-time string constants, not just string literals. If the template is not a string literal, use parenthesis to indicate that it is not an opcode.

Unlike i386 inline assembler statements, extended assembler statements do not prevent a function from being inlined.

See the GCC manual for more information about this extension.

Example:

uint invert(uint v)
{
    uint result;
    version(X86)
       asm{ "notl %[iov]" : [iov] "=r" result : "0" v; }
    else version(PPC)
       asm{ "nor %[oresult],%[iv],%[iv]" : [oresult] "=r" result : [iv] "r" v; }
    return result;
}

Known Issues

See our issue tracker to see bugs that have been reported to GDC.

More bugs may be found here.

Some more known issues, taken from here:

  • See the DStress page for known failing cases. (Again, may be irrelevant)
  • Debugging information may have a few problems. For D symbol name demangling you need at least gdb 7.2.
  • Some targets do not support once-only linking. A workaround is to manually control template emission. See the -femit-templates option below. For Darwin, Apple's GCC 3.x compiler supports one-only linking, but GDC does not build with those sources. There are no problems with the stock GCC 4.x on Darwin.
  • Complex floating point operations may not work the same as DMD.
  • Some math functions behave differently due to different implementations of the extended floating-point type.
  • Volatile statements may not always do the right thing.
  • Because of a problem on AIX, the linker will pull in more modules than needed.
  • Some C libraries (Cygwin, MinGW, AIX) don't handle floating-point formatting and parsing in a standard way.

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.