Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
752 lines (566 sloc) 25.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 Linux - 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 - Linux D Compiler</h1>
<li>dmd for <a href="dmd-windows.html">Windows</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="#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="#dmd_conf">dmd.conf</a> Initialization File</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 x86 Linux operating system (will work on 64 bit Linux)</li>
<li>Gnu C compiler (gcc)</li>
<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/linux/bin/<a href="">dumpobj</a></tt>
<dd>Elf file dumper</dd>
<dt><tt>dmd2/linux/bin/<a href="">obj2asm</a></tt>
<dd>Elf file disassembler</dd>
<dt><tt>dmd2/linux/bin/<a href="">shell</a></tt>
<dd>Simple command line shell</dd>
<dt><tt>dmd2/linux/bin/<a href="#dmd_conf">dmd.conf</a></tt>
<dd>Global compiler settings (copy to <tt>/etc/dmd.conf</tt>)</dd>
<dd>D runtime library (copy to <tt>/usr/lib/libphobos2.a</tt>)</dd>
<h2><a name="installation">Installation</a></h2>
<li>Unzip the archive into your home directory.
It will create
a <tt>~/dmd</tt> directory with all the files in it.
All the tools are command line tools, which means
they are run from a console window.</li>
<li>Copy <tt><a href="#dmd_conf">dmd.conf</a></tt> to <tt>/etc</tt>:
<pre class="console"><span class="notranslate">cp dmd2/linux/bin/<a href="#dmd_conf">dmd.conf</a> /etc
<li>Put <tt>dmd2/linux/bin</tt> on your <b>PATH</b>,
or copy the linux executables
to <tt>/usr/local/bin</tt></li>
<li>Copy the library to <tt>/usr/lib</tt>:
<pre class="console"><span class="notranslate">cp dmd2/linux/lib/libphobos2.a /usr/lib
<h3>Installing dmd on 64 bit Linux</h3>
<p>Since dmd is a 32 bit compiler, the 32 bit gnu libraries must be installed:</p>
<pre class="console"><span class="notranslate">sudo apt-get install gcc-multilib g++-multilib libc6-i386 libc6-dev-i386
<p>The <tt>ia32-libs</tt> package has more 32 bit libraries, and may
optionally also be installed:</p>
<pre class="console"><span class="notranslate">sudo apt-get install ia32-libs
<p>If you are using the .deb package for one-click install, it may
give you an error about it being only for i386. To force it to install:
<pre class="console"><span class="notranslate">sudo dpkg -i --force-architecture dmd_X.XXX-0_i386.deb
<p>where X.XXX is the version number of the package.
<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>.o</b></td>
<td>Object files to link in</td>
<tr> <td><b>.a</b></td>
<td>Object code libraries to search</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>libphobos2.a</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>libphobos2.a</b>
<dt><b>-deps=</b><i>filename</i></dt><dd> write module dependencies as text to <i>filename</i>
<dt><b>-fPIC</b></dt><dd> generate Position Independent Code (which is used
for building shared libraries).
add Dwarf symbolic debug info with
<a href="abi.html#dwarf">D extensions</a>
for debuggers such as
<a href="">ZeroBUGS</a>
add Dwarf 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
linker, 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.
open browser specified by the <b>BROWSER</b>
environment variable on this page. If <b>BROWSER</b> is
undefined, <b>x-www-browser</b> is assumed.
<dt><b>-noboundscheck</b></dt><dd> turns off all array bounds checking, even for safe functions
<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 .o 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>
<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 actual linking is done by running <b>gcc</b>.
This ensures compatibility with modules compiled with <b>gcc</b>.
<h2><a name="environment">Environment Variables</a></h2>
<p>The D compiler dmd uses the following environment variables:
<dd> <b>dmd</b> normally runs the linker by looking for <b>gcc</b>
along the <b>PATH</b>. To use a specific linker instead, set the
<b>CC</b> environment variable to it. For example:
<pre class="console"><span class="notranslate">set CC=gcc
<dd>This sets the browser used to open the manual page with
the <b>-man</b> switch. It defaults to <tt>x-www-browser</tt>.
<dd>The value of <b>DFLAGS</b> is treated as if it were appended to the
command line to <b>dmd</b>.
<h2><a name="dmd_conf">dmd.conf Initialization File</a></h2>
<p>The dmd file <tt>dmd.conf</tt> is the same as <tt>sc.ini</tt>
for Windows, it's just that the file has a different name,
enabling a setup common to both Windows and this system to be created
without having to re-edit the file.</p>
<p><b>dmd</b> will look for the initialization file <tt>dmd.conf</tt> 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</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.
<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">; 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.
DFLAGS=-I%@P%/../src/phobos -I%@P%/../src/druntime/import
<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.o</tt> and existing library
<tt>def.a</tt> which are
all to be combined into a library <tt>foo.a</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
rm -f foo.a
ar -r foo.a foo.o bar.o abc.o def.a
rm foo.o bar.o
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
rm -f foo.a
ar -r foo.a foo.o bar.o abc.o def.a
rm foo.o bar.o
<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.o def.a
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 linux.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 posix.mak DMD=~/dmd2/linux/bin/dmd
cd ../phobos
make -f linux.mak DMD=~/dmd2/linux/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>.