Find file
Fetching contributors…
Cannot retrieve contributors at this time
804 lines (613 sloc) 27.9 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
<html lang="en-US">
Copyright (c) 1999-2011 by Digital Mars
All Rights Reserved Written by Walter Bright
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="keywords" content="D programming language" />
<meta name="description" content="D Programming Language" />
<title>DMD Compiler for Windows - D Programming Language 2.0 - Digital Mars</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/print.css" media="print" />
<link rel="shortcut icon" href="favicon.ico" />
<!-- enable this for automated hyphenation, see -->
<script src="" type="text/javascript"></script>
<script type="text/javascript">;</script>
<script type="text/javascript">
function bodyLoad()
var links = document.getElementById("navigation").getElementsByTagName("a");
for (var i = 0; i < links.length; i++)
var url = "/" + links[i].getAttribute("href");
if (window.location.href.match(url + "\x24") == url)
var cls = links[i].getAttribute("class");
links[i].setAttribute("class", cls ? cls + " active" : "active");
<body onload="bodyLoad()">
<div id="top">
<form method="get" action="">
<div id="search-box">
<img src="images/search-left.gif" width="11" height="22" /><input id="q" name="q" /><input type="image" id="search-submit" name="submit" src="images/search-button.gif" />
<input type="hidden" id="domains" name="domains" value="" />
<input type="hidden" id="sourceid" name="sourceid" value="google-search" />
<div id="search-dropdown">
<select id="sitesearch" name="sitesearch" size="1">
<option value="">Entire D 2.0 Site</option>
<option value="">Library Reference</option>
<option value="">Newsgroup Archives</option>
<div id="header">
<a href=""><img id="logo" width="253" height="37" border="0" alt="Digital Mars" src="images/dmlogo.gif"></a>
<div id="d-language"><a href="">D Programming Language 2.0</a></div>
<!-- Generated by Ddoc from dcompiler.dd -->
<div id="navigation">
<div class="navblock">
<h2><a href="index.html" title="D Programming Language">D 2.0 Home</a></h2>
<ul> <li><a href="overview.html" title="D language overview">Overview</a></li>
<li><a href="comparison.html" title="D feature list">Features</a></li>
<li><a href="download.html" title="Download a D compiler">Downloads &amp; Tools</a>
<div class="navblock">
<ul> <li><a href="dmd-linux.html" title="dmd - the Digital Mars D compiler">DMD D Compiler (Linux)</a></li>
<li><a href="dmd-freebsd.html" title="dmd - the Digital Mars D compiler">DMD D Compiler (FreeBSD)</a></li>
<li><a href="dmd-osx.html" title="dmd - the Digital Mars D compiler">DMD D Compiler (Mac OSX)</a></li>
<li><a href="dmd-windows.html" title="dmd - the Digital Mars D compiler">DMD D Compiler (Windows)</a></li>
<li><a href="changelog.html" title="History of changes to D">D Change Log</a></li>
<li><a href="" title="gdc - the Gnu D compiler">GDC D Compiler</a></li>
<li><a href="" title="D Compiler for .NET">D.NET Compiler</a></li>
<li><a href="" title="Optlink - the Digital Mars Linker">Linker</a></li>
<li><a href="" title="DMD's builtin code profiling tool">Profiler</a></li>
<li><a href="code_coverage.html" title="DMD's builtin code coverage analysis tool">Code Coverage</a></li>
<li><a href="rdmd.html" title="rdmd - run D programs as if they were scripts">DMD Script Shell</a></li>
<li><a href="windbg.html" title="windbg - debugging Windows programs">Windows Debugger</a></li>
<li><a href="htod.html" title="htod - mechanically convert C .h header files to D">C .h to D .d</a></li>
<li><a href="" title="Editors with support for D">Editors</a></li>
<li><a href="" title="Even more tools for D">More Tools</a></li>
<li><a href="" title="D issue and bug tracking system">Issues &amp; Bugs</a></li>
<li><a href="faq.html" title="Frequently Asked Questions">FAQ</a></li>
<li><a href="appendices.html">Appendices</a></li>
<li><a href="acknowledgements.html" title="Thank-you to these people who have helped with D">Acknowledgements</a></li>
<li><a href="" title="D Programming Language 1.0">D1 Home</a></li>
<div class="navblock">
<ul> <li><a href="language-reference.html">Language Reference</a></li>
<li><a href="phobos/index.html">Library Reference</a></li>
<li><a href="howtos.html" title="Helps for using D">Howtos</a></li>
<li><a href="articles.html">Articles</a></li>
<div class="navblock">
<ul> <li><a href="" title="User forums">Forums</a></li>
<li><a href="" title="Wiki for the D Programming Language">Wiki</a></li>
<li><a href="" title="D projects and libraries at">Projects &amp; Libraries</a></li>
<li><a href="" title="#d_lang on">Twitter</a></li>
<li><a href="" title="External D related links">Links</a></li>
<div id="translate" class="tool"><script type="text/javascript">document.write("Translate this page:")</script>
<div id="google_translate_element"></div><script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
autoDisplay: false,
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
</script><script type="text/javascript" src=""></script>
<div id="content">
<div id="tools">
<span id="lastupdate">Last update Sat Jan 29 18:52:17 2011
<span id="wiki"><a href="">Comment on this page</a></span>
<h1> dmd - Windows D Compiler</h1>
<ul> <li>dmd for <a href="dmd-linux.html"> Linux</a></li>
<li>dmd for <a href="dmd-osx.html"> OSX</a></li>
<li>dmd for <a href="dmd-freebsd.html">FreeBSD</a></li>
<li><a href="#requirements">Requirements and Downloads</a></li>
<li><a href="#files">Files</a></li>
<li><a href="#installation">Installation</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#switches">Compiler Arguments and Switches</a></li>
<li><a href="#linking">Linking</a></li>
<li><a href="#environment">Environment Variables</a></li>
<li><a href="#sc_ini">sc.ini Initialization File</a></li>
<li><a href="#problems">Common Installation Problems</a></li>
<li><a href="#differences">Differences between Windows and Linux versions</a></li>
<li><a href="#interface_files">D Interface Files</a></li>
<li><a href="#library">Building Libraries</a></li>
<li><a href="#compiling_dmd">Compiling dmd</a></li>
<li><a href="#compiling_phobos">Compiling Phobos</a></li>
<h2><a name="requirements">Requirements and Downloads</a></h2>
<ol><li><a href="">Download D Compiler</a></li>
<li>32 bit Windows (Win32) operating system, such as Windows XP</li>
<a href="" title="download"> (C and C++ compiler)</a> for Win32
(not required, but it complements dmd for Windows)
<h2><a name="files">Files</a></h2>
<dl> <dt><tt>\dmd2\src\phobos\</tt>
<dd>D runtime library source</dd>
<dd>D compiler front end source under dual (GPL and Artistic) license</dd>
<dd>Sample D programs</dd>
<dd>D compiler executable</dd>
<dt><tt>\dmd2\windows\bin\<a href="">shell.exe</a></tt>
<dd>Simple command line shell</dd>
<dd>Global compiler settings</dd>
<dd>D runtime library</dd>
<h2><a name="installation">Installation</a></h2>
<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></tt> will create
a <tt>\dmd2</tt> directory with all the files in it.
<tt></tt> will create
a <tt>\dm</tt> directory with all the files in it.
<p>A typical session might look like:</p>
<pre class="console"><span class="notranslate">C:\Documents and Settings\Your Name&gt;cd \
<pre class="console"><span class="notranslate">\dmd2\windows\bin\<a href="">shell</a>
<p>in the <tt>\dmd2\samples\d</tt> directory for several small examples.</p>
<h2><a name="switches">Compiler Arguments and Switches</a></h2>
<dl> <dt><b>dmd</b> <i>files</i>... -<i>switches</i>...
<dd> <table border=1 cellpadding=4 cellspacing=0><caption>File Extensions</caption> <tr> <th scope="col">Extension</th>
<th scope="col">File Type</th>
<tr> <td><i>none</i></td>
<td>D source files</td>
<tr> <td><b>.d</b></td>
<td>D source files</td>
<tr> <td><b>.dd</b></td>
<td><a href="ddoc.html">Ddoc</a> source files</td>
<tr> <td><b>.di</b></td>
<td><a href="#interface_files">D interface files</a></td>
<tr> <td><b>.obj</b></td>
<td>Object files to link in</td>
<tr> <td><b>.lib</b></td>
<td>Object code libraries to search</td>
<tr> <td><b>.exe</b></td>
<td>Output executable file</td>
<tr> <td><b>.def</b></td>
<td><a href="">module definition file</a></td>
<tr> <td><b>.res</b></td>
<td>resource file</td>
<dt><b>@</b><i>cmdfile</i></dt><dd> If <i>cmdfile</i> is an environment variable,
read the compiler arguments and switches from
the value of that variable.
Otherwise, read compiler arguments and switches from
the text file <i>cmdfile</i>
<dt><b>-c</b></dt><dd> compile only, do not link
<dt><b>-cov</b></dt><dd> instrument for <a href="code_coverage.html">code coverage analysis</a>
<dt><b>-D</b></dt><dd> generate <a href="ddoc.html">documentation</a> from source
<dt><b>-Dd</b><i>docdir</i></dt><dd> write documentation file to <i>docdir</i> directory
<dt><b>-Df</b><i>filename</i></dt><dd> write documentation file to <i>filename</i>
<dt><b>-d</b></dt><dd> allow deprecated features
<dt><b>-debug</b></dt><dd> compile in <a href="version.html#debug">debug</a> code
<dt><b>-debug=</b><i>level</i></dt><dd> compile in <a href="version.html#debug">debug level</a> &lt;= <i>level</i>
<dt><b>-debug=</b><i>ident</i></dt><dd> compile in <a href="version.html#debug">debug identifier</a> <i>ident</i>
<dt><b>-debuglib=</b><i>libname</i></dt><dd> link in <i>libname</i> as the default library when
compiling for symbolic debugging instead of <b>phobos.lib</b>
<dt><b>-defaultlib=</b><i>libname</i></dt><dd> link in <i>libname</i> as the default library when
not compiling for symbolic debugging instead of <b>phobos.lib</b>
<dt><b>-deps=</b><i>filename</i></dt><dd> write module dependencies as text to <i>filename</i>
<dt><b>-g</b></dt><dd> add CodeView 4 symbolic debug info with
<a href="abi.html#codeview">D extensions</a>
for debuggers such as
<a href="">Ddbg</a>
<dt><b>-gc</b></dt><dd> add CodeView 4 symbolic debug info in C format
for debuggers such as
<dt><b>-H</b></dt><dd> generate <a href="#interface_files">D interface file</a>
<dt><b>-Hd</b><i>dir</i></dt><dd> write D interface file to <i>dir</i> directory
<dt><b>-Hf</b><i>filename</i></dt><dd> write D interface file to <i>filename</i>
<dt><b>--help</b></dt><dd> print brief help to console
<dt><b>-inline</b></dt><dd> inline expand functions at the discretion of the compiler.
This can improve performance, at the expense of making
it more difficult to use a debugger on it.
<dt><b>-I</b><i>path</i></dt><dd> where to look for
<a href="module.html#ImportDeclaration">imports</a>.
<i>path</i> is a ; separated
list of paths. Multiple <b>-I</b>'s can be used, and the paths
are searched in the same order.
<dt><b>-ignore</b></dt><dd> ignore unsupported pragmas
<dt><b>-J</b><i>path</i></dt><dd> where to look for files for
<a href="expression.html#ImportExpression"><i>ImportExpression</i></a>s.
This switch is required in order to use <i>ImportExpression</i>s.
<i>path</i> is a ; separated
list of paths. Multiple <b>-J</b>'s can be used, and the paths
are searched in the same order.
<dt><b>-L</b><i>linkerflag</i></dt><dd> pass <i>linkerflag</i> to the
<a href="">linker</a>
, for example,
<dt><b>-lib</b></dt><dd> generate library file as output instead of object file(s).
All compiled source files, as well as object files and library
files specified on the command line, are inserted into
the output library.
Compiled source modules may be partitioned into several object
modules to improve granularity.
The name of the library is taken from the name of the first
source module to be compiled. This can be overridden with
the <b>-of</b> switch.
<dt><b>-man</b></dt><dd> open default browser on this page
<dt><b>-noboundscheck</b></dt><dd> turns off all array bounds checking, even for safe functions
<dt><b>-nofloat</b></dt><dd> Prevents emission of <b>__fltused</b> reference in
object files, even if floating point code is present.
Useful for library code.
<dt><b>-O</b></dt><dd> Optimize generated code. For fastest executables, compile
with the <b>-O -release -inline</b> switches together.
<dt><b>-o-</b></dt><dd> Suppress generation of object file. Useful in
conjuction with <b>-D</b> or <b>-H</b> flags.
<dt><b>-od</b><i>objdir</i></dt><dd> <dd>write object files relative to directory <i>objdir</i>
instead of to the current directory</dd>
<dt><b>-of</b><i>filename</i></dt><dd> Set output file name to <i>filename</i> in the output
directory. The output file can be an object file,
executable file, or library file depending on the other
<dt><b>-op</b></dt><dd> normally the path for <b>.d</b> source files is stripped
off when generating an object file name. <b>-op</b> will leave
it on.
<dt><b>-profile</b></dt><dd> <a href="">profile</a>
the runtime performance
of the generated code
<dt><b>-quiet</b></dt><dd> suppress non-essential compiler messages
compile release version, which means not generating
code for contracts and asserts. Array bounds checking
is not done for system and trusted functions.
<dt><b>-run</b> <i>srcfile args...</i>
compile</dt><dd>link, and run the program <i>srcfile</i> with the
rest of the
command line, <i>args...</i>, as the arguments to the program.
No .obj or executable file is left behind.
<dt><b>-unittest</b></dt><dd> compile in <a href="unittest.html">unittest</a> code, turns on asserts, and sets the
<tt>unittest</tt> <a href="version.html#PredefinedVersions">version identifier</a>
<dt><b>-v</b></dt><dd> verbose
<dt><b>-vtls</b></dt><dd> print informational messages identifying variables defaulting
to thread local storage. Handy for migrating to shared model.
<dt><b>-version=</b><i>level</i></dt><dd> compile in <a href="version.html#version">version level</a> &gt;= <i>level</i>
<dt><b>-version=</b><i>ident</i></dt><dd> compile in <a href="version.html#version">version identifier</a> <i>ident</i>
<dt><b>-w</b></dt><dd> enable <a href="warnings.html">warnings</a>
<dt><b>-wi</b></dt><dd> enable <a href="warnings.html">informational warnings (i.e. compilation
still proceeds normally)</a>
<p>Empty switches, i.e. "", are ignored.</p>
<h2><a name="linking">Linking</a></h2>
<p>Linking is done directly by the <b>dmd</b> compiler after a successful
compile. To prevent <b>dmd</b> from running the linker, use the
<b>-c</b> switch.
<p>The programs must be linked with the D runtime library <b>phobos.lib</b>,
followed by the C runtime library <b>snn.lib</b>.
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:
<pre class="console"><span class="notranslate">set LIB=\dmd2\lib;\dm\lib
<p>If the <b>dmd</b> command is used to both compile and link
to an executable, it will make certain optimizations that are
valid only for Windows executable files. Do not use the resulting
.obj files in a DLL.
To compile modules into .obj files that can be used in an exe or
DLL, compile with <b>-c</b>.
<p>Linking is done using the
<a href="">optlink</a> linker.
<h2><a name="environment">Environment Variables</a></h2>
<p>The D compiler dmd uses the following environment variables:
<dl> <dt><b>DFLAGS</b>
<dd>The value of <b>DFLAGS</b> is treated as if it were appended to the
command line to <b>dmd.exe</b>.
<dd>The linker uses <b>LIB</b> to search for library files. For D, it will
normally be set to:
<pre class="console"><span class="notranslate">set LIB=\dmd2\lib;\dm\lib
<dd> <b>dmd</b> normally runs the linker by looking for <b>link.exe</b>
along the <b>PATH</b>. To use a specific linker instead, set the
<b>LINKCMD</b> environment variable to it. For example:
<pre class="console"><span class="notranslate">set LINKCMD=\dmd\windows\bin\link
<dd>If the linker is not found in the same directory as <b>dmd.exe</b>
is in, the <b>PATH</b> is searched for it.
<b>Note:</b> other linkers named
<b>link.exe</b> will likely not work.
Make sure the Digital Mars <b>link.exe</b>
is found first in the <b>PATH</b> before other <b>link.exe</b>'s,
or use <b>LINKCMD</b> to specifically identify which linker
to use.
<h2><a name="sc_ini">sc.ini Initialization File</a></h2>
<p><b>dmd</b> will look for the initialization file <b>sc.ini</b> in the
following sequence of directories:
<ol><li>current working directory</li>
<li>directory specified by the <b>HOME</b> environment variable</li>
<li>directory <b>dmd.exe</b> resides in</li>
<p>If found, environment variable
settings in the file will override any existing settings.
This is handy to make <b>dmd</b> independent of programs with
conflicting use of environment variables.
<h3>Initialization File Format</h3>
<p>Comments are lines that begin with <tt>;</tt> and are ignored.
<p>Environment variables follow the <tt>[Environment]</tt> section
heading, in <i>NAME</i>=<i>value</i> pairs.
The <i>NAME</i>s are treated as upper case.
Comments are lines that start with ;.
For example:
<pre class="scini"><span class="notranslate">; 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.
DFLAGS="-I%@P%\..\src\phobos" "-I%@P%\..\src\druntime\import"
<h3>Location Independence of sc.ini</h3>
<p>The <b>%@P%</b> is replaced with the path to <tt>sc.ini</tt>.
Thus, if the fully qualified file name <tt>sc.ini</tt> is
<tt>c:\dmd2\bin\sc.ini</tt>, then <b>%@P%</b> will be replaced with
<tt>c:\dmd2\bin</tt>, and the above <tt>sc.ini</tt> will be
interpreted as:
<pre class="scini"><span class="notranslate">[Environment]
DFLAGS="-Ic:\dmd2\bin\..\src\phobos" "-Ic:\dmd2\bin\..\src\druntime\import"
<p>This enables your dmd setup to be moved around without having
to re-edit <tt>sc.ini</tt>.
<h2><a name="problems">Common Installation Problems</a></h2>
<ul> <li>Using Cygwin's <b>unzip</b> 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</b> before trying Cygwin's.
<li>Installing <b>dmd</b> and <b>dmc</b> into directory paths with spaces
in them causes problems.
<h2><a name="differences">Differences between Windows and Linux versions</a></h2>
<ul> <li>String literals are read-only under Linux.
Attempting to write to them
will cause a segment violation.</li>
<h2><a name="interface_files">D Interface Files</a></h2>
<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</i>.
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>
<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.</li>
<p>D interface files can be created by the compiler from a
D source file by using the <b>-H</b> switch to the compiler.
D interface files have the <b>.di</b> file extension.
When the compiler resolves an import declaration, it first looks
for a <b>.di</b> D interface file, then it looks for a D source
<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.
<h2><a name="executable">Building Executables</a></h2>
<p><b>dmd</b> can build an executable much faster if as many of the
source files as possible are put on the command line.</p>
<p>Another advantage to putting multiple source files on the same
invocation of <b>dmd</b> is that <b>dmd</b> will be able to do some level
of cross-module optimizations, such as function inlining across modules.
<h2><a name="library">Building Libraries</a></h2>
<p>There are three ways to build a library. For example,
given <tt>foo.d</tt> and <tt>bar.d</tt> which are to be compiled, and existing
object file <tt>bar.obj</tt> and existing library
<tt>def.lib</tt> which are
all to be combined into a library <tt>foo.lib</tt>:</p>
<ol><li>Compile modules separately and then run the librarian on them:
<pre class="console"><span class="notranslate">dmd -c foo.d
dmd -c bar.d
<a href="">lib</a> -c -p32 foo.lib foo.obj bar.obj abc.obj def.lib
del foo.obj bar.obj
This option is typical when using a makefile to avoid compiling
modules that have already been compiled.
<li>Compile modules together and then run the librarian on them:
<pre class="console"><span class="notranslate">dmd -c foo.d bar.d
<a href="">lib</a> -c -p32 foo.lib foo.obj bar.obj abc.obj def.lib
del foo.obj bar.obj
<li>Use <b>dmd</b> to compile and build library in one operation:
<pre class="console"><span class="notranslate">dmd -lib foo.d bar.d abc.obj def.lib
No object files are written to disk, it's all done in memory.
Using <b>-lib</b> also has the advantage that modules may be compiled
into multiple object files rather than exactly one per module.
This improves granularity of the library without having to break
up the modules.
<h2><a name="compiling_dmd">Compiling dmd</a></h2>
<p>Complete source code is provided to build the compiler.
Follow these steps:</p>
<pre class="console"><span class="notranslate">cd \dmd2\src\dmd
make -f win32.mak
<h2><a name="compiling_phobos">Compiling Phobos</a></h2>
<p>Complete source code is provided to build Phobos, the D runtime library.
Follow these steps:</p>
<pre class="console"><span class="notranslate">cd \dmd2\src\druntime
make -f win32.mak DMD=\dmd2\windows\bin\dmd
cd ..\phobos
make -f win32.mak DMD=\dmd2\windows\bin\dmd
<div id="google_ad">
<!-- Google ad -->
<script type="text/javascript"><!--
/**/google_ad_client = "pub-5628673096434613";
/**/google_ad_width = 728;
/**/google_ad_height = 90;
/**/google_ad_format = "728x90_as";
/**/google_ad_channel ="3651639259";
/**/google_page_url = document.location;
<script type="text/javascript" src="">
<div id="footernav">
<a href="" title="User Forums">Forums</a> |
<a href="" title="Read/write comments and feedback">Comments</a> |
<a href="index.html" title="D Programming Language" class="dlink">&nbsp;D&nbsp;</a> |
<a href="" title="Search Digital Mars web site">Search</a> |
<a href="download.html" title="Download D">Downloads</a> |
<a href="" title="">Home</a>
<div id="copyright">
Copyright &copy; 1999-2011 by Digital Mars &reg;, All Rights Reserved |
Page generated by <a href="ddoc.html">Ddoc</a>.