forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmd-freebsd.html
727 lines (550 loc) · 25 KB
/
dmd-freebsd.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
<!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 FreeBSD - 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 & 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 & 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 & 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:18 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 - FreeBSD D Compiler</h1>
<ul>
<li>dmd for <a href="dmd-windows.html">Windows</a></li>
<li>dmd for <a href="dmd-linux.html"> Linux</a></li>
<li>dmd for <a href="dmd-osx.html"> OSX</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>
</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 x86 FreeBSD 7.1 operating system</li>
<li>Gnu C compiler (gcc)</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/freebsd/bin/dmd</tt>
<dd>D compiler executable</dd>
</dt>
<dt><tt>dmd2/freebsd/bin/<a href="http://www.digitalmars.com/ctg/dumpobj.html">dumpobj</a></tt>
<dd>Elf file dumper</dd>
</dt>
<dt><tt>dmd2/freebsd/bin/<a href="http://www.digitalmars.com/ctg/obj2asm.html">obj2asm</a></tt>
<dd>Elf file disassembler</dd>
</dt>
<dt><tt>dmd2/freebsd/bin/<a href="http://www.digitalmars.com/ctg/shell.html">shell</a></tt>
<dd>Simple command line shell</dd>
</dt>
<dt><tt>dmd2/freebsd/bin/<a href="#dmd_conf">dmd.conf</a></tt>
<dd>Global compiler settings (copy to <tt>/etc/dmd.conf</tt>)</dd>
</dt>
<dt><tt>dmd2/freebsd/lib/libphobos2.a</tt>
<dd>D runtime library (copy to <tt>/usr/lib/libphobos2.a</tt>)</dd>
</dt>
</dl>
<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/freebsd/bin/dmd.conf /etc
</span></pre>
</li>
<li>Put <tt>dmd2/freebsd/bin</tt> on your <b>PATH</b>,
or copy the FreeBSD 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/freebsd/lib/libphobos2.a /usr/lib
</span></pre>
</li>
<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>.o</b></td>
<td>Object files to link in</td>
</tr>
<tr> <td><b>.a</b></td>
<td>Object code libraries to search</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> <= <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>libphobos2.a</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>libphobos2.a</b>
</dd>
<dt><b>-deps=</b><i>filename</i></dt><dd> write module dependencies as text to <i>filename</i>
</dd>
<dt><b>-fPIC</b></dt><dd> generate Position Independent Code (which is used
for building shared libraries).
</dd>
<dt><b>-g</b></dt><dd>
add Dwarf symbolic debug info with
<a href="abi.html#dwarf">D extensions</a>
for debuggers
</dd>
<dt><b>-gc</b></dt><dd>
add Dwarf symbolic debug info in C format
for debuggers such as
<tt>gdb</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
linker, for example,
<tt>-L-M</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 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.
</dd>
<dt><b>-noboundscheck</b></dt><dd> turns off all array bounds checking, even for safe functions
</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 .o 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> >= <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>
<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 actual linking is done by running <b>gcc</b>.
This ensures compatibility with modules compiled with <b>gcc</b>.
</p>
<h2><a name="environment">Environment Variables</a></h2>
<p>The D compiler dmd uses the following environment variables:
</p>
<dl>
<dt><b>CC</b>
<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
</span></pre>
<dt><b>BROWSER</b>
<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>
</dt>
<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</b>.
</dl>
<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>
<li><tt>/etc/</tt></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>
<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">; 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 -I%@P%/../src/druntime/import
</span></pre>
<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.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
</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
rm -f foo.a
ar -r foo.a foo.o bar.o abc.o def.a
rm foo.o bar.o
</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.o def.a
</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 freebsd.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 posix.mak DMD=~/dmd2/freebsd/bin/dmd
cd ../phobos
make -f freebsd.mak DMD=~/dmd2/freebsd/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"> D </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 © 1999-2011 by Digital Mars ®, All Rights Reserved |
Page generated by <a href="ddoc.html">Ddoc</a>.
</div>
</body>
</html>