Ddoc $(D_S Compiler for D Programming Language, $(UL $(LI D for Win32) $(LI D for x86 Linux) $(LI general) )

Downloads

$(LINK2 http://www.digitalmars.com/d/download.html, Download D Compiler)

Files Common to Win32 and Linux

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

DMD Win32 D Compiler

Requirements and Downloads

$(UL $(LI 32 bit Windows (Win32) operating system, such as Windows XP) $(LI Download dmd) $(LI Download dmc.zip (linker and utilities) for Win32 ) )

Files

$(DL $(DT $(TT \dmd\bin\dmd.exe) $(DD D compiler executable) ) $(DT $(TT \dmd\bin\shell.exe) $(DD Simple command line shell) ) $(DT $(TT \dmd\bin\sc.ini) $(DD Global compiler settings) ) $(DT $(TT \dmd\lib\phobos.lib) $(DD D runtime library) ) )

Installation

$(P 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. $(TT dmd.zip) will create a $(TT \dmd) directory with all the files in it. $(TT dmc.zip) will create a $(TT \dm) directory with all the files in it. ) $(P A typical session might look like:) $(CONSOLE C:\Documents and Settings\Your Name>cd \ C:\>unzip dmd.zip C:\>unzip dmc.zip )

Example

$(P Run:) $(CONSOLE \dmd\bin\shell all.sh ) $(P in the $(TT \dmd\samples\d) directory for several small examples.)

Compiler Arguments and Switches

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

Linking

$(P Linking is done directly by the $(B dmd) compiler after a successful compile. To prevent $(B dmd) from running the linker, use the $(B -c) switch. ) $(P The programs must be linked with the D runtime library $(B phobos.lib), followed by the C runtime library $(B 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: ) $(CONSOLE set LIB=\dmd\lib;\dm\lib )

Environment Variables

$(P The D compiler dmd uses the following environment variables: ) $(DL
$(B DFLAGS)
The value of $(B DFLAGS) is treated as if it were appended to the command line to $(B dmd.exe).
$(B LIB)
The linker uses $(B LIB) to search for library files. For D, it will normally be set to: $(CONSOLE set LIB=\dmd\lib;\dm\lib )
$(B LINKCMD)
$(B dmd) normally runs the linker by looking for $(B link.exe) along the $(B PATH). To use a specific linker instead, set the $(B LINKCMD) environment variable to it. For example: $(CONSOLE set LINKCMD=\dm\bin\link )
$(B PATH)
If the linker is not found in the same directory as $(B dmd.exe) is in, the $(B PATH) is searched for it. $(B Note:) other linkers named $(B link.exe) will likely not work. Make sure the Digital Mars $(B link.exe) is found first in the $(B PATH) before other $(B link.exe)'s, or use $(B LINKCMD) to specifically identify which linker to use. )

sc.ini Initialization File

$(P $(B dmd) will look for the initialization file $(B sc.ini) in the following sequence of directories: ) $(OL $(LI current working directory) $(LI directory specified by the $(B HOME) environment variable) $(LI directory $(B dmd.exe) resides in) ) $(P If found, environment variable settings in the file will override any existing settings. This is handy to make $(B dmd) independent of programs with conflicting use of environment variables. )

Initialization File Format

$(P Comments are lines that begin with $(TT ;) and are ignored. ) $(P Environment variables follow the $(TT [Environment]) section heading, in $(I NAME)=$(I value) pairs. The $(I NAME)s are treated as upper case. Comments are lines that start with ;. For example: ) $(SCINI ; 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 )

Location Independence of sc.ini

$(P The $(B %@P%) is replaced with the path to $(TT sc.ini). Thus, if the fully qualified file name $(TT sc.ini) is $(TT c:\dmd\bin\sc.ini), then $(B %@P%) will be replaced with $(TT c:\dmd\bin), and the above $(TT sc.ini) will be interpreted as: ) $(SCINI [Environment] LIB="c:\dmd\bin\..\lib";\dm\lib DFLAGS="-Ic:\dmd\bin\..\src\phobos" LINKCMD="c:\dmd\bin\..\..\dm\bin" DDOCFILE=mysettings.ddoc ) $(P This enables your dmd setup to be moved around without having to re-edit $(TT sc.ini). )

Common Installation Problems

$(UL $(LI Using Cygwin's $(B unzip) utility has been known to cause strange problems. ) $(LI 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 $(B cmd.exe) before trying Cygwin's. ) $(LI Installing $(B dmd) and $(B dmc) into directory paths with spaces in them causes problems. ) )

Linux D Compiler

Requirements and Downloads

$(UL $(LI 32 bit x86 Linux operating system) $(LI Download dmd) $(LI Gnu C compiler (gcc)) )

Files

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

Installation

$(OL $(LI Unzip the archive into your home directory. It will create a $(TT ~/dmd) directory with all the files in it. All the tools are command line tools, which means they are run from a console window.) $(LI Copy $(TT dmd.conf) to $(TT /etc): $(CONSOLE cp dmd/bin/dmd.conf /etc ) ) $(LI Give execute permission to the following files: $(CONSOLE chmod u+x dmd/bin/{dmd,dumpobj,obj2asm,rdmd} ) ) $(LI Put $(TT dmd/bin) on your $(B PATH), or copy the linux executables to $(TT /usr/local/bin)) $(LI Copy the library to $(TT /usr/lib): $(CONSOLE cp dmd/lib/$(LIB) /usr/lib ) ) )

Compiler Arguments and Switches

$(B dmd) $(I files)... -$(I switch)...

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

Linking

$(P Linking is done directly by the $(B dmd) compiler after a successful compile. To prevent $(B dmd) from running the linker, use the $(B -c) switch. ) $(P The actual linking is done by running $(B gcc). This ensures compatibility with modules compiled with $(B gcc). )

Environment Variables

The D compiler dmd uses the following environment variables: $(DL
$(B CC)
$(B dmd) normally runs the linker by looking for $(B gcc) along the $(B PATH). To use a specific linker instead, set the $(B CC) environment variable to it. For example: $(CONSOLE set CC=gcc )
$(B DFLAGS)
The value of $(B DFLAGS) is treated as if it were appended to the command line to $(B dmd). )

dmd.conf Initialization File

$(P The Linux dmd file $(TT dmd.conf) is the same as $(TT sc.conf) for Windows, it's just that the file has a different name, enabling a setup common to both Windows and Linux to be created without having to re-edit the file.) $(P $(B dmd) will look for the initialization file $(B dmd.conf) in the following sequence of directories:) $(OL $(LI current working directory) $(LI directory specified by the $(B HOME) environment variable) $(LI directory $(B dmd) resides in) $(LI $(B /etc/)) ) $(P If found, environment variable settings in the file will override any existing settings. This is handy to make $(B dmd) independent of programs with conflicting use of environment variables. ) $(P Environment variables follow the $(TT [Environment]) section heading, in $(I NAME)=$(I value) pairs. The $(I NAME)s are treated as upper case. Comments are lines that start with ;. For example: ) $(SCINI ; 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

$(UL $(LI String literals are read-only. Attempting to write to them will cause a segment violation.) $(LI The configuration file is $(TT /etc/dmd.conf)) )

General

D Interface Files

$(P 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 $(I D interface file). A D interface file contains only what an import of the module needs, rather than the whole implementation of that module. ) $(P The advantages of using a D interface file for imports rather than a D source file are: ) $(UL $(LI D interface files are often significantly smaller and much faster to process than the corresponding D source file.) $(LI 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.) ) $(P D interface files can be created by the compiler from a D source file by using the $(B -H) switch to the compiler. D interface files have the $(B .di) file extension. When the compiler resolves an import declaration, it first looks for a $(B .di) D interface file, then it looks for a D source file. ) $(P 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. ) ) Macros: TITLE=DMD Compiler WIKI=DCompiler LIB=$(V1 libphobos.a)$(V2 libphobos2.a)