Last update March 7, 2012

D Tutorial / Starting With D / Compiler /
DMD



This page is here to instruct you in the installation and use of the Digital Mars D compiler (DMD). There is more than one way to install programs: the simplest is the 1-click method, but there is a more detailed 'universal' method.

Table of contents of this page
Installation   
1-Click Installers   
Universal Install   
Windows   
Linux   
System Install   
Using Bash Script   
AMD64   
Ubuntu   
Arch Linux   
Mac OS X   
Compiling Programs   
Related   

Installation    

1-Click Installers    

The download page now has 1-click installers for Win32, Ubuntu, and Linux rpm. (For example, the Windows version takes you through a wizard, downloads and installs the software, and sets the PATH.)

Universal Install    

This older method works across all platforms with only slight differences because of how the PATH is handle across platforms.

  1. Download the zip file and extract it to your location of choice.
  2. You're done. You can now compile programs from the terminal.
To improve on this situation you can just create a script that is located somewhere included in your PATH. Or set your path to include: /path/to/bin

Windows dmd.bat:

 

Linux dmd.sh:

#!/bin/bash
/lib/ld-linux.so.2 /path/to/bin/dmd $*

Windows    

Follow the Universal directions above. Then to set the path:

  • On Windows 2000 and newer, use the System or My Computer Properties/Advanced tab/Environment Variables button, and add the paths to the end of the system path for allusers. Separate paths using a semicolon.
You will also want to make sure that you do not have Microsoft's "Link.exe" in any directory listed in your %PATH%. It will conflict with DM's "Link.exe". Otherwise you'll receive the error "OPTLINK Error: 118: Filename Expected" when you try to add symbolic debug info (e.g. "dmd -g hello.d").

Linux    

System Install    

You can use the DEB/RPM packages or follow these manual instructions.

D2.x
The base directory for D2.x is in dmd2/ not dmd/

  1. Download and unzip, like above (you can do this from any directory)
  2. Install the linux executables to /usr/local/bin (and make them executable too)
    install -p -m 0755 dmd/linux/bin/dmd dmd/linux/bin/obj2asm dmd/linux/bin/dumpobj /usr/local/bin
  3. Install the manpages to /usr/local/man (under the man1 subdirectory)
    install -p -m 0644 dmd/man/man1/dmd.1 dmd/man/man1/obj2asm.1 dmd/man/man1/dumpobj.1 /usr/local/man/man1
  4. Install the library to /usr/local/lib:
    install -p -m 0644 dmd/lib/libphobos.a /usr/local/lib
  5. You can install all the Phobos import modules to a directory like /usr/local/src/phobos
    mkdir -p /usr/local/src/phobos
    (cd dmd/src/phobos; find -name '*.d' | xargs tar c) | (cd /usr/local/src/phobos; tar xv)
Sample /etc/dmd.conf:
 [Environment]

DFLAGS=-I/usr/local/src/phobos -L-L/usr/local/lib

Using Bash Script    

You can also choose to use a bash script created to handle installation and updating of DMD.

install-d
Install DMD
install-tango
Install Tango, expects DMD to have been installed with install-d
dmd-switch
If you have installed two of the following DMD 1.x, 2.x, or Tango with the above scripts, this allows you to choose what will be used when calling $ dmd

AMD64    

Since DMD is not yet 64bit after you do the installation you will need a few more packages. The packages are similar on all distributions, below are some distro specific instructions:

Ubuntu    

sudo aptitude install gcc-multilib libc6-i386 lib6-dev-i386

Also you may need the 32bit libraries to run your compiled program.

sudo aptitude install ia32-libs

Arch Linux    

If you have gcc-multilib installed, you should remove it before starting:

$ sudo pacman -Rd gcc-multilib

You can then use:

$ yaourt -S cross32-gcc

To install cross32-gcc from AUR. See http://wiki.archlinux.org/index.php/Yaourt for how to install yaourt. You should now edit your dmd.conf and make sure it uses the 32bit gcc for linking, by adding the following in the [Environment] section:

 CC=/usr/bin/i686-unknown-linux-gnu-gcc

Your dmd.conf should now look something like:

  [Environment]

  DFLAGS=-I%@P%/../../src/phobos -L-L%@P%/../lib 
  CC=/usr/bin/i686-unknown-linux-gnu-gcc

Mac OS X    

Compiling Programs    

Compiling just requires calling dmd and listing your source files. As a project grows this can be troublesome so there have been many build tools created to automate this.

Windows:

dmd.exe prog.d

Linux/Mac OS X:

dmd prog.d

If it worked the result is cryptic, but pretty boring.

Output on Windows:

d:\dmd\bin\..\..\dm\bin\link.exe nothing,,,user32+kernel32/noi;

Output on Linux:

gcc nothing.o -o nothing -lphobos -lpthread -lm

Output on Mac OS X: (i.e. nothing at all, nice and quiet)

Related    


FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: March 7, 2012 20:21 (diff))