D Programming Language 2.0

- Comments
- D
- Search
- Downloads
- Home

Last update Wed Oct 17 15:41:33 2007

# Compiler for D Programming Language

- D for Win32
- D for x86 Linux
- general

## Downloads

- Download latest version of dmd.zip (D compiler) for Win32 and Linux
- Download dmc.zip (linker and utilities) for Win32
- To download specific versions of dmd, see the changelog.

## Files Common to Win32 and Linux

`\dmd\src\phobos\`
  D runtime library source
`\dmd\src\dmd\`
  D compiler front end source under dual (GPL and Artistic) license
`\dmd\html\d\`
  Documentation
`\dmd\samples\d\`
  Sample D programs

# Win32 D Compiler

## Requirements and Downloads

- 32 bit Windows (Win32) operating system, such as Windows XP
- Download dmd.zip (D compiler) for Win32
  - Mirror: dreamhosters
  - Mirror: puremagic (torrent)
  - Mirror: puremagic (http)
  - Mirror: 63.99.9.206
- Download dmc.zip (linker and utilities) for Win32

## Files

`\dmd\bin\dmd.exe`
  D compiler executable
`\dmd\bin\shell.exe`
  Simple command line shell
`\dmd\bin\sc.ini`
  Global compiler settings
`\dmd\lib\phobos.lib`
  D runtime library

## Installation

Open a console window (for Windows XP this is done by clicking on [Start][Command Prompt]). All the tools are command line tools, which means they are run from a console window. Switch to the root directory. Unzip the files in the root directory. `dmd.zip` will create a `\dmd` directory with all the files in it. `dmc.zip` will create a `\dm` directory with all the files in it.

A typical session might look like:

    C:\Documents and Settings\Your Name>cd \
    C:\>unzip dmd.zip
    C:\>unzip dmc.zip

## Example

Run:

    \dmd\bin\shell all.sh

in the `\dmd\samples\d` directory for several small examples.

## Compiler Arguments and Switches

dmd files... -switches...

files...

  Extension | File Type
  --- | ---
  none | D source files
  .d | D source files
  .di | D interface files
  .obj | Object files to link in
  .lib | Object code libraries to search
  .exe | Name output executable file
  .def | module definition file
  .res | resource file

@cmdfile
  reads compiler arguments and switches from text file cmdfile
-c
  compile only, do not link
-cov
  instrument for code coverage analysis
-D
  Generate documentation from source.
-Dd docdir
  write documentation file to docdir directory
-Df filename
  write documentation file to filename
-d
  allow deprecated features
-debug
  compile in debug code
-debug=level
  compile in debug code <= level
-debug=ident
  compile in debug code identified by ident
-debuglib=libname
  link in libname as the default library when compiling for symbolic debugging instead of phobos.lib
-defaultlib=libname
  link in libname as the default library when not compiling for symbolic debugging instead of phobos.lib
-g
  add CodeView 4 symbolic debug info
-gc
  add CodeView 4 symbolic debug info in C format (for C debuggers)
-H
  generate D interface file
-Hd dir
  write D interface file to dir directory
-Hf filename
  write D interface file to filename
--help
  print help
-inline
  inline expand functions
-I path
  where to look for imports. path is a ; separated list of paths. Multiple -I's can be used, and the paths are searched in the same order.
-J path
  where to look for files for ImportExpressions. This switch is required in order to use ImportExpressions. path is a ; separated list of paths. Multiple -J's can be used, and the paths are searched in the same order.
-L linkerflag
  pass linkerflag to the linker, for example, `/ma/li`
-nofloat
  Prevents emission of __fltused reference in object files, even if floating point code is present. Useful for library code. Windows only.
-O
  Optimize generated code.
-o-
  Suppress generation of object file. Useful in conjuction with -D or -H flags.
-od objdir
  write object files relative to directory objdir instead of to the current directory
-of filename
  set output file name to filename in the output directory
-op
  normally the path for .d source files is stripped off when generating an object file name. -op will leave it on.
-profile
  profile the runtime performance of the generated code
-quiet
  suppress non-essential compiler messages
-release
  compile release version, which means not generating code for contracts and asserts
-run srcfile args...
  compile, link, and run the program srcfile with the rest of the command line, args..., as the arguments to the program. No .obj or .exe file is left behind.
-unittest
  compile in unittest code, also turns on asserts
-v
  verbose
-version=level
  compile in version code >= level
-version=ident
  compile in version code identified by ident
-w
  enable warnings

## Linking

Linking is done directly by the dmd compiler after a successful compile. To prevent dmd from running the linker, use the -c switch.

The programs must be linked with the D runtime library phobos.lib, followed by the C runtime library snn.lib. This is done automatically as long as the directories for the libraries are on the LIB environment variable path. A typical way to set LIB would be:

    set LIB=\dmd\lib;\dm\lib

## Environment Variables

The D compiler dmd uses the following environment variables:

DFLAGS
  The value of DFLAGS is treated as if it were appended to the command line to dmd.exe.
LIB
  The linker uses LIB to search for library files. For D, it will normally be set to:

      set LIB=\dmd\lib;\dm\lib

LINKCMD
  dmd normally runs the linker by looking for link.exe along the PATH. To use a specific linker instead, set the LINKCMD environment variable to it. For example:

      set LINKCMD=\dm\bin\link

PATH
  If the linker is not found in the same directory as dmd.exe is in, the PATH is searched for it. Note: other linkers named link.exe will likely not work. Make sure the Digital Mars link.exe is found first in the PATH before other link.exe's, or use LINKCMD to specifically identify which linker to use.

## sc.ini Initialization File

dmd will look for the initialization file sc.ini in the following sequence of directories:

1. current working directory
2. directory specified by the HOME environment variable
3. directory dmd.exe resides in

If found, environment variable settings in the file will override any existing settings. This is handy to make dmd independent of programs with conflicting use of environment variables.

Environment variables follow the `[Environment]` section heading, in NAME=value pairs. The NAMEs are treated as upper case. Comments are lines that start with ;. For example:

    ; sc.ini file for dmd
    ; Names enclosed by %% are searched for in the existing environment
    ; and inserted. The special name %@P% is replaced with the path
    ; to this file.
    [Environment]
    LIB="%@P%\..\lib";\dm\lib
    DFLAGS="-I%@P%\..\src\phobos"
    LINKCMD="%@P%\..\..\dm\bin"
    DDOCFILE=mysettings.ddoc

## Common Installation Problems

- Using Cygwin's unzip utility has been known to cause strange problems.
- Running the compiler under Cygwin's command shell has been also known to cause problems. Try getting it to work under the regular Windows shell cmd.exe before trying Cygwin's.
- Installing dmd and dmc into directory paths with spaces in them causes problems.

# Linux D Compiler

## Requirements and Downloads

- 32 bit x86 Linux operating system
- Download dmd.zip (D compiler) for Linux
  - Mirror: dreamhosters
  - Mirror: puremagic (torrent)
  - Mirror: puremagic (http)
  - Mirror: 63.99.9.206
- Gnu C compiler (gcc)

## Files

`/dmd/bin/dmd`
  D compiler executable
`/dmd/bin/dumpobj`
  Elf file dumper
`/dmd/bin/obj2asm`
  Elf file disassembler
`/dmd/bin/dmd.conf`
  Global compiler settings (copy to `/etc/dmd.conf`)
`/dmd/lib/libphobos.a`
  D runtime library (copy to `/usr/lib/libphobos.a`)

## Installation

1. Unzip the archive into your home directory. It will create a `~/dmd` directory with all the files in it. All the tools are command line tools, which means they are run from a console window.
2. Copy `dmd.conf` to `/etc`:

       cp dmd/bin/dmd.conf /etc

3. Give execute permission to the following files:

       chmod u+x dmd/bin/{dmd,dumpobj,obj2asm,rdmd}

4. Put `dmd/bin` on your PATH, or copy the linux executables to `/usr/local/bin`
5. Copy the library to `/usr/lib`:

       cp dmd/lib/libphobos.a /usr/lib

## Compiler Arguments and Switches

dmd files... -switch...

files...

  Extension | File Type
  --- | ---
  none | D source files
  .d | D source files
  .di | D interface files
  .o | Object files to link in
  .a | Library files to link in

-c
  compile only, do not link
-cov
  instrument for code coverage analysis
-D
  generate documentation
-Dd docdir
  write documentation file to docdir directory
-Df filename
  write documentation file to filename
-d
  allow deprecated features
-debug
  compile in debug code
-debug=level
  compile in debug code <= level
-debug=ident
  compile in debug code identified by ident
-debuglib=libname
  link in libname as the default library when compiling for symbolic debugging instead of libphobos2.a
-defaultlib=libname
  link in libname as the default library when not compiling for symbolic debugging instead of libphobos2.a
-fPIC
  generate position independent code
-g
  add symbolic debug info
-gc
  add symbolic debug info in C format (for older gdb's)
-H
  generate D interface file
-Hd dir
  write D interface file to dir directory
-Hf filename
  write D interface file to filename
--help
  print help
-inline
  inline expand functions
-I path
  where to look for imports. path is a ; separated list of paths. Multiple -I's can be used, and the paths are searched in the same order.
-J path
  where to look for files for ImportExpressions. This switch is required in order to use ImportExpressions. path is a ; separated list of paths. Multiple -J's can be used, and the paths are searched in the same order.
-L linkerflag
  pass linkerflag to the linker, for example, `-M`
-O
  optimize
-o-
  suppress generation of object file
-od objdir
  write object files relative to directory objdir instead of to the current directory
-of filename
  set output file name to filename in the output directory
-op
  normally the path for .d source files is stripped off when generating an object file name. -op will leave it on.
-quiet
  suppress non-essential compiler messages
-profile
  profile the runtime performance of the generated code
-release
  compile release version
-run srcfile args...
  compile, link, and run the program srcfile with the rest of the command line, args..., as the arguments to the program. No .o or executable file is left behind.
-unittest
  compile in unittest code
-v
  verbose
-version=level
  compile in version code >= level
-version=ident
  compile in version code identified by ident
-w
  enable warnings

## Linking

Linking is done directly by the dmd compiler after a successful compile. To prevent dmd from running the linker, use the -c switch.

The actual linking is done by running gcc. This ensures compatibility with modules compiled with gcc.

## Environment Variables

The D compiler dmd uses the following environment variables:

CC
  dmd normally runs the linker by looking for gcc along the PATH. To use a specific linker instead, set the CC environment variable to it. For example:

      set CC=gcc

DFLAGS
  The value of DFLAGS is treated as if it were appended to the command line to dmd.

## dmd.conf Initialization File

dmd will look for the initialization file dmd.conf in the following sequence of directories:

1. current working directory
2. directory specified by the HOME environment variable
3. directory dmd resides in
4. /etc/

If found, environment variable settings in the file will override any existing settings. This is handy to make dmd independent of programs with conflicting use of environment variables.

Environment variables follow the `[Environment]` section heading, in NAME=value pairs. The NAMEs are treated as upper case. Comments are lines that start with ;. For example:

    ; dmd.conf file for dmd
    ; Names enclosed by %% are searched for in the existing environment
    ; and inserted. The special name %@P% is replaced with the path
    ; to this file.
    [Environment]
    DFLAGS="-I%@P%/../src/phobos"

## Differences from Win32 version

- String literals are read-only. Attempting to write to them will cause a segment violation.
- The configuration file is `/etc/dmd.conf`

# General

## D Interface Files

When an import declaration is processed in a D source file, the compiler searches for the D source file corresponding to the import, and processes that source file to extract the information needed from it. Alternatively, the compiler can instead look for a corresponding D interface file. A D interface file contains only what an import of the module needs, rather than the whole implementation of that module.

The advantages of using a D interface file for imports rather than a D source file are:

- D interface files are often significantly smaller and much faster to process than the corresponding D source file.
- They can be used to hide the source code, for example, one can ship an object code library along with D interface files rather than the complete source code.

D interface files can be created by the compiler from a D source file by using the -H switch to the compiler. D interface files have the .di file extension. When the compiler resolves an import declaration, it first looks for a .di D interface file, then it looks for a D source file.

D interface files bear some analogous similarities to C++ header files. But they are not required in the way that C++ header files are, and they are not part of the D language. They are a feature of the compiler, and serve only as an optimization of the build process.

Copyright © 1999-2007 by Digital Mars, All Rights Reserved | Page generated by Ddoc. | Comments