Permalink
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" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<!--
Copyright (c) 1999-2011 by Digital Mars
All Rights Reserved Written by Walter Bright
http://www.digitalmars.com
-->
<head>
<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 http://code.google.com/p/hyphenator/ -->
<!--
<script src="http://erdani.com/js/Hyphenator.js" type="text/javascript"></script>
<script type="text/javascript">Hyphenator.run();</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");
break;
}
}
}
</script>
</head>
<body onload="bodyLoad()">
<div id="top">
<form method="get" action="http://www.google.com/search">
<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="www.digitalmars.com" />
<input type="hidden" id="sourceid" name="sourceid" value="google-search" />
<div id="search-dropdown">
<select id="sitesearch" name="sitesearch" size="1">
<option value="www.digitalmars.com/d/2.0">Entire D 2.0 Site</option>
<option value="www.digitalmars.com/d/2.0/phobos">Library Reference</option>
<option value="www.digitalmars.com/d/archives">Newsgroup Archives</option>
</select>
</div>
</div>
</form>
<div id="header">
<a href="http://www.digitalmars.com"><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>
</div>
</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="http://bitbucket.org/goshawk/gdc/wiki/Home" title="gdc - the Gnu D compiler">GDC D Compiler</a></li>
<li><a href="http://dnet.codeplex.com/" title="D Compiler for .NET">D.NET Compiler</a></li>
<li><a href="http://www.digitalmars.com/ctg/optlink.html" title="Optlink - the Digital Mars Linker">Linker</a></li>
<li><a href="http://www.digitalmars.com/ctg/trace.html" 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="http://www.prowiki.org/wiki4d/wiki.cgi?EditorSupport" title="Editors with support for D">Editors</a></li>
<li><a href="http://www.prowiki.org/wiki4d/wiki.cgi?ReferenceForTools" title="Even more tools for D">More Tools</a></li>
<li><a href="http://d.puremagic.com/issues/" title="D issue and bug tracking system">Issues &amp; Bugs</a></li>
</ul>
</div>
</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="http://www.digitalmars.com/d/1.0/index.html" title="D Programming Language 1.0">D1 Home</a></li>
</ul>
</div>
<div class="navblock">
<h2>Documentation</h2>
<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>
</ul>
</div>
<div class="navblock">
<h2>Community</h2>
<ul> <li><a href="http://www.digitalmars.com/NewsGroup.html" title="User forums">Forums</a></li>
<li><a href="http://www.prowiki.org/wiki4d/wiki.cgi?FrontPage" title="Wiki for the D Programming Language">Wiki</a></li>
<li><a href="http://www.dsource.org/" title="D projects and libraries at dsource.org">Projects &amp; Libraries</a></li>
<li><a href="http://twitter.com/#search?q=%23d_lang" title="#d_lang on twitter.com">Twitter</a></li>
<li><a href="http://www.digitalmars.com/d/dlinks.html" title="External D related links">Links</a></li>
</ul>
</div>
<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="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</div>
</div>
<div id="content">
<div id="tools">
<span id="lastupdate">Last update Sat Jan 29 18:52:17 2011
</span>
<span id="wiki"><a href="http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/DCompiler">Comment on this page</a></span>
</div>
<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>
</ul>
<h2><a name="requirements">Requirements and Downloads</a></h2>
<ol><li><a href="http://www.digitalmars.com/d/download.html">Download D Compiler</a></li>
<li>32 bit Windows (Win32) operating system, such as Windows XP</li>
<li>Download
<a href="http://ftp.digitalmars.com/dmc.zip" title="download dmc.zip">
dmc.zip (C and C++ compiler)</a> for Win32
(not required, but it complements dmd for Windows)
</li>
</ol>
<h2><a name="files">Files</a></h2>
<dl> <dt><tt>\dmd2\src\phobos\</tt>
<dd>D runtime library source</dd>
</dt>
<dt><tt>\dmd2\src\dmd\</tt>
<dd>D compiler front end source under dual (GPL and Artistic) license</dd>
</dt>
<dt><tt>\dmd2\html\d\</tt>
<dd>Documentation</dd>
</dt>
<dt><tt>\dmd2\samples\d\</tt>
<dd>Sample D programs</dd>
</dt>
<dt><tt>\dmd2\windows\bin\dmd.exe</tt>
<dd>D compiler executable</dd>
</dt>
<dt><tt>\dmd2\windows\bin\<a href="http://www.digitalmars.com/ctg/shell.html">shell.exe</a></tt>
<dd>Simple command line shell</dd>
</dt>
<dt><tt>\dmd2\windows\bin\sc.ini</tt>
<dd>Global compiler settings</dd>
</dt>
<dt><tt>\dmd2\windows\lib\phobos.lib</tt>
<dd>D runtime library</dd>
</dt>
</dl>
<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>dmd.zip</tt> will create
a <tt>\dmd2</tt> directory with all the files in it.
<tt>dmc.zip</tt> will create
a <tt>\dm</tt> directory with all the files in it.
</p>
<p>A typical session might look like:</p>
<pre class="console"><span class="notranslate">C:\Documents and Settings\Your Name&gt;cd \
C:\&gt;unzip dmd.zip
C:\&gt;unzip dmc.zip
</span></pre>
<h2>Example</h2>
<p>Run:</p>
<pre class="console"><span class="notranslate">\dmd2\windows\bin\<a href="http://www.digitalmars.com/ctg/shell.html">shell</a> all.sh
</span></pre>
<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></dd>
</dt>
<dt><i>files</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>
<tr> <td><i>none</i></td>
<td>D source files</td>
</tr>
<tr> <td><b>.d</b></td>
<td>D source files</td>
</tr>
<tr> <td><b>.dd</b></td>
<td><a href="ddoc.html">Ddoc</a> source files</td>
</tr>
<tr> <td><b>.di</b></td>
<td><a href="#interface_files">D interface files</a></td>
</tr>
<tr> <td><b>.obj</b></td>
<td>Object files to link in</td>
</tr>
<tr> <td><b>.lib</b></td>
<td>Object code libraries to search</td>
</tr>
<tr> <td><b>.exe</b></td>
<td>Output executable file</td>
</tr>
<tr> <td><b>.def</b></td>
<td><a href="http://www.digitalmars.com/ctg/ctgDefFiles.html">module definition file</a></td>
</tr>
<tr> <td><b>.res</b></td>
<td>resource file</td>
</tr>
</table>
</dd>
</dt>
<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>
</dd>
<dt><b>-c</b></dt><dd> compile only, do not link
</dd>
<dt><b>-cov</b></dt><dd> instrument for <a href="code_coverage.html">code coverage analysis</a>
</dd>
<dt><b>-D</b></dt><dd> generate <a href="ddoc.html">documentation</a> from source
</dd>
<dt><b>-Dd</b><i>docdir</i></dt><dd> write documentation file to <i>docdir</i> directory
</dd>
<dt><b>-Df</b><i>filename</i></dt><dd> write documentation file to <i>filename</i>
</dd>
<dt><b>-d</b></dt><dd> allow deprecated features
</dd>
<dt><b>-debug</b></dt><dd> compile in <a href="version.html#debug">debug</a> code
</dd>
<dt><b>-debug=</b><i>level</i></dt><dd> compile in <a href="version.html#debug">debug level</a> &lt;= <i>level</i>
</dd>
<dt><b>-debug=</b><i>ident</i></dt><dd> compile in <a href="version.html#debug">debug identifier</a> <i>ident</i>
</dd>
<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>
</dd>
<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>
</dd>
<dt><b>-deps=</b><i>filename</i></dt><dd> write module dependencies as text to <i>filename</i>
</dd>
<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="http://ddbg.mainia.de/releases.html">Ddbg</a>
</dd>
<dt><b>-gc</b></dt><dd> add CodeView 4 symbolic debug info in C format
for debuggers such as
<tt>\dmd2\bin\windbg</tt>
</dd>
<dt><b>-H</b></dt><dd> generate <a href="#interface_files">D interface file</a>
</dd>
<dt><b>-Hd</b><i>dir</i></dt><dd> write D interface file to <i>dir</i> directory
</dd>
<dt><b>-Hf</b><i>filename</i></dt><dd> write D interface file to <i>filename</i>
</dd>
<dt><b>--help</b></dt><dd> print brief help to console
</dd>
<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.
</dd>
<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.
</dd>
<dt><b>-ignore</b></dt><dd> ignore unsupported pragmas
</dd>
<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.
</dd>
<dt><b>-L</b><i>linkerflag</i></dt><dd> pass <i>linkerflag</i> to the
<a href="http://www.digitalmars.com/ctg/optlink.html">linker</a>
, for example,
<tt>-L/ma/li</tt>
</dd>
<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.
</dd>
<dt><b>-man</b></dt><dd> open default browser on this page
</dd>
<dt><b>-noboundscheck</b></dt><dd> turns off all array bounds checking, even for safe functions
</dd>
<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.
</dd>
<dt><b>-O</b></dt><dd> Optimize generated code. For fastest executables, compile
with the <b>-O -release -inline</b> switches together.
</dd>
<dt><b>-o-</b></dt><dd> Suppress generation of object file. Useful in
conjuction with <b>-D</b> or <b>-H</b> flags.
</dd>
<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>
</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
switches.
</dd>
<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.
</dd>
<dt><b>-profile</b></dt><dd> <a href="http://www.digitalmars.com/ctg/trace.html">profile</a>
the runtime performance
of the generated code
</dd>
<dt><b>-quiet</b></dt><dd> suppress non-essential compiler messages
</dd>
<dt><b>-release</b></dt><dd>
compile release version, which means not generating
code for contracts and asserts. Array bounds checking
is not done for system and trusted functions.
</dd>
<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.
</dd>
<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>
</dd>
<dt><b>-v</b></dt><dd> verbose
</dd>
<dt><b>-vtls</b></dt><dd> print informational messages identifying variables defaulting
to thread local storage. Handy for migrating to shared model.
</dd>
<dt><b>-version=</b><i>level</i></dt><dd> compile in <a href="version.html#version">version level</a> &gt;= <i>level</i>
</dd>
<dt><b>-version=</b><i>ident</i></dt><dd> compile in <a href="version.html#version">version identifier</a> <i>ident</i>
</dd>
<dt><b>-w</b></dt><dd> enable <a href="warnings.html">warnings</a>
</dd>
<dt><b>-wi</b></dt><dd> enable <a href="warnings.html">informational warnings (i.e. compilation
still proceeds normally)</a>
</dd>
</dl>
<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>
<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:
</p>
<pre class="console"><span class="notranslate">set LIB=\dmd2\lib;\dm\lib
</span></pre>
<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>
<p>Linking is done using the
<a href="http://www.digitalmars.com/ctg/optlink.html">optlink</a> linker.
</p>
<h2><a name="environment">Environment Variables</a></h2>
<p>The D compiler dmd uses the following environment variables:
</p>
<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>.
<dt><b>LIB</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
</span></pre>
<dt><b>LINKCMD</b>
<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
</span></pre>
<dt><b>PATH</b>
<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.
</dl>
<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:
</p>
<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>
</ol>
<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.
</p>
<h3>Initialization File Format</h3>
<p>Comments are lines that begin with <tt>;</tt> and are ignored.
</p>
<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:
</p>
<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.
[Environment]
LIB="%@P%\..\lib";\dm\lib
DFLAGS="-I%@P%\..\src\phobos" "-I%@P%\..\src\druntime\import"
LINKCMD="%@P%\..\..\dm\bin"
DDOCFILE=mysettings.ddoc
</span></pre>
<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:
</p>
<pre class="scini"><span class="notranslate">[Environment]
LIB="c:\dmd2\bin\..\lib";\dm\lib
DFLAGS="-Ic:\dmd2\bin\..\src\phobos" "-Ic:\dmd2\bin\..\src\druntime\import"
LINKCMD="c:\dmd2\bin\..\..\dm\bin"
DDOCFILE=mysettings.ddoc
</span></pre>
<p>This enables your dmd setup to be moved around without having
to re-edit <tt>sc.ini</tt>.
</p>
<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>
<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>
<li>Installing <b>dmd</b> and <b>dmc</b> into directory paths with spaces
in them causes problems.
</li>
</ul>
<hr>
<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>
</ul>
<hr>
<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>
<p>The advantages of using a D interface file for imports rather
than a D source file are:
</p>
<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>
</ul>
<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
file.
</p>
<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.
</p>
<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.
</p>
<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="http://www.digitalmars.com/ctg/lib.html">lib</a> -c -p32 foo.lib foo.obj bar.obj abc.obj def.lib
del foo.obj bar.obj
</span></pre>
This option is typical when using a makefile to avoid compiling
modules that have already been compiled.
</li>
<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="http://www.digitalmars.com/ctg/lib.html">lib</a> -c -p32 foo.lib foo.obj bar.obj abc.obj def.lib
del foo.obj bar.obj
</span></pre>
</li>
<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
</span></pre>
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.
</li>
</ol>
<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
</span></pre>
<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
</span></pre>
<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>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</div>
<div id="footernav">
<a href="http://www.digitalmars.com/NewsGroup.html" title="User Forums">Forums</a> |
<a href="http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/DCompiler" title="Read/write comments and feedback">Comments</a> |
<a href="index.html" title="D Programming Language" class="dlink">&nbsp;D&nbsp;</a> |
<a href="http://www.digitalmars.com/advancedsearch.html" title="Search Digital Mars web site">Search</a> |
<a href="download.html" title="Download D">Downloads</a> |
<a href="http://www.digitalmars.com/" title="www.digitalmars.com">Home</a>
</div>
<div id="copyright">
Copyright &copy; 1999-2011 by Digital Mars &reg;, All Rights Reserved |
Page generated by <a href="ddoc.html">Ddoc</a>.
</div>
</body>
</html>