Difference between revisions of "Installing DMD"

From D Wiki
Jump to: navigation, search
(Update Arch package install info)
 
(7 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  
 
== Windows ==
 
== Windows ==
By default, DMD on Windows is distributed as a 32-bit application and is configured to compile 32-bit binaries. It ships with the OPTLINK linker, the same linker used by the Digital Mars C/C++ compiler. This linker produces object files in the [https://en.wikipedia.org/wiki/Relocatable_Object_Module_Format OMF format], making it incompatible with objects produced by linkers in other modern C and C++ compiler packages on Windows, which typically use the [https://en.wikipedia.org/wiki/COFF MS-COFF format]. However, if the Microsoft compiler toolchain is installed, DMD can be configured to make use of it and produce, and link, object files in the MS-COFF format.
+
By default, DMD on Windows is distributed as a 32-bit application and is configured to compile 32-bit binaries. It ships with the OPTLINK linker, the same linker used by the Digital Mars C/C++ compiler. This linker consumes object files in the [https://en.wikipedia.org/wiki/Relocatable_Object_Module_Format OMF format], making it incompatible with objects produced by linkers in other modern C and C++ compiler packages on Windows, which typically use the [https://en.wikipedia.org/wiki/COFF MS-COFF format]. However, if the Microsoft compiler toolchain is installed, DMD can be configured to make use of it and produce, and link, object files in the MS-COFF format.
  
 
=== The DMD installer ===
 
=== The DMD installer ===
The installer for Windows linked from the [https://dlang.org/download.html download page] is by far the easiest way to install DMD on Windows. If Visual Studio is installed, it will automatically detect the installation and modify DMD's configuration file, then offer to install [http://rainers.github.io/visuald/visuald/StartPage.html Visual D], the Visual Studio plugin for D. If no VS installation is found, it will offer to install Visual Studio 2013 Express. It also offers the option of installing the D1 compiler and, finally, will ask permission to configure the system path.
+
The installer for Windows linked from the [https://dlang.org/download.html download page] is by far the easiest way to install DMD on Windows. If Visual Studio is installed, it will automatically detect the installation and modify DMD's configuration file, then offer to install [http://rainers.github.io/visuald/visuald/StartPage.html Visual D], the Visual Studio plugin for D. If no VS installation is found, it will offer to install Visual Studio 2013 Community. It also offers the option of installing the D1 compiler and, finally, will ask permission to configure the system path.
  
 
Visual Studio is not required to use DMD's default configuration. However, for modern Windows development, it's a practical necessity. The offer to install VS 2013 is intended for compatibility with all supported Windows systems, but it's not recommended on Windows 8 and later. Users should prefer to install the most recent version of Visual Studio for their system (see the section,  
 
Visual Studio is not required to use DMD's default configuration. However, for modern Windows development, it's a practical necessity. The offer to install VS 2013 is intended for compatibility with all supported Windows systems, but it's not recommended on Windows 8 and later. Users should prefer to install the most recent version of Visual Studio for their system (see the section,  
Line 16: Line 16:
  
 
=== Installing the Microsoft toolchain ===
 
=== Installing the Microsoft toolchain ===
For any user who does not already have Visual studio installed, the Community Edition of Visual Studio, since its introduction with the VS 2015 release, is the preferred package for obtaining the Microsoft toolchain. It installs everything DMD needs to produce binaries in the MS-COFF format, including the Windows SDK. Windows 10 users should prefer the [https://www.visualstudio.com/ 2017 edition], as the installer allows the selection of only the components required, minimizing the download size and installation time.
+
For any user who does not already have Visual Studio installed, the Community Edition of Visual Studio, since its introduction with the VS 2015 release, is the preferred package for obtaining the Microsoft toolchain. It installs everything DMD needs to produce binaries in the MS-COFF format, including the Windows SDK. Windows 10 users should prefer the [https://www.visualstudio.com/ 2017 edition], as the installer allows the selection of only the components required, minimizing the download size and installation time:
 +
[[File:Visual_Studio_Installer.png|800px|center]]
  
 
Prior to the Community Edition, the Visual Studio Express editions were the only Visual Studio distributions that did not require a commercial license. These editions do not ship with the Windows SDK. Anyone installing on Windows 7 and 8 should prefer to install VS 2015 Community. Windows 10 users should prefer VS 2017 Community. When installing on Windows Vista, it is likely easier to allow the DMD installer to install VS 2013 automatically.
 
Prior to the Community Edition, the Visual Studio Express editions were the only Visual Studio distributions that did not require a commercial license. These editions do not ship with the Windows SDK. Anyone installing on Windows 7 and 8 should prefer to install VS 2015 Community. Windows 10 users should prefer VS 2017 Community. When installing on Windows Vista, it is likely easier to allow the DMD installer to install VS 2013 automatically.
Line 42: Line 43:
 
echo %UCRTVersion%
 
echo %UCRTVersion%
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
Note that the last two are specific to the Windows 10 SDK and will not be present when an older versions of the SDK is installed. In that case, they can be safely ignored.
  
 
Once that's accomplished, turn to the next two commented blocks immediately beneath the one you just edited.
 
Once that's accomplished, turn to the next two commented blocks immediately beneath the one you just edited.
Line 61: Line 64:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Find the line matching your version of Visual Studio, or the Build Tools, and remove the semic-colon and version number from that line. For example, if you installed the 2015 Build Tools, change the following two lines:
+
Find the line matching your version of Visual Studio, or the Build Tools, and remove the semi-colon and version number from that line. For example, if you installed the 2015 Build Tools, change the following two lines:
  
 
<syntaxhighlight lang="ini">
 
<syntaxhighlight lang="ini">
Line 72: Line 75:
  
 
<syntaxhighlight lang="ini">
 
<syntaxhighlight lang="ini">
;VC2015 LINKCMD=%VCINSTALLDIR%\bin\x86_amd64\link.exe
+
LINKCMD=%VCINSTALLDIR%\bin\x86_amd64\link.exe
  
;VC2015 PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\bin
+
PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\bin
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 83: Line 86:
  
 
== Arch Linux ==
 
== Arch Linux ==
There is a package in community repository for [https://www.archlinux.org/packages/community/i686/dmd/ 32 bit dmd] and [https://www.archlinux.org/packages/community/x86_64/dmd/ | 64 bit dmd].
+
There are packages in the community repository for [https://www.archlinux.org/groups/x86_64/dlang/ dmd, dub, ldc and other D tools]. Install them using pacman:
 +
 
 +
<syntaxhighlight lang="bash">
 +
pacman -S dmd
 +
</syntaxhighlight>
  
 
== Gentoo Linux ==
 
== Gentoo Linux ==

Latest revision as of 09:45, 4 March 2018

The official DMD Downloads page provides several options for downloading and installing the compiler, including an installer for Windows, platform-specific packages for Linux distributions, a dmg file for OS X, and compressed archives for all supported platforms. Additionally, a command line is provided that can be entered into a Bash shell to fetch an install script.

The sections below list known options for obtaining DMD for each platform, along with any platform specific details that should be taken into consideration.

Windows

By default, DMD on Windows is distributed as a 32-bit application and is configured to compile 32-bit binaries. It ships with the OPTLINK linker, the same linker used by the Digital Mars C/C++ compiler. This linker consumes object files in the OMF format, making it incompatible with objects produced by linkers in other modern C and C++ compiler packages on Windows, which typically use the MS-COFF format. However, if the Microsoft compiler toolchain is installed, DMD can be configured to make use of it and produce, and link, object files in the MS-COFF format.

The DMD installer

The installer for Windows linked from the download page is by far the easiest way to install DMD on Windows. If Visual Studio is installed, it will automatically detect the installation and modify DMD's configuration file, then offer to install Visual D, the Visual Studio plugin for D. If no VS installation is found, it will offer to install Visual Studio 2013 Community. It also offers the option of installing the D1 compiler and, finally, will ask permission to configure the system path.

Visual Studio is not required to use DMD's default configuration. However, for modern Windows development, it's a practical necessity. The offer to install VS 2013 is intended for compatibility with all supported Windows systems, but it's not recommended on Windows 8 and later. Users should prefer to install the most recent version of Visual Studio for their system (see the section, 'Installing the Microsoft toolchain') before running the DMD installer.

The compressed archive

DMD is also distributed on Windows as an archive compressed with the 7z format. This can be extracted to any directory (C:\D is the default path used by the installer), which can then be manually added to the system path. If MS-COFF support is desired, the DMD configuration file will need to be manually edited to point to the installation of the Microsoft build tools and SDK (see the section, 'Installing the Microsoft toolchain').

Installing the Microsoft toolchain

For any user who does not already have Visual Studio installed, the Community Edition of Visual Studio, since its introduction with the VS 2015 release, is the preferred package for obtaining the Microsoft toolchain. It installs everything DMD needs to produce binaries in the MS-COFF format, including the Windows SDK. Windows 10 users should prefer the 2017 edition, as the installer allows the selection of only the components required, minimizing the download size and installation time:

Visual Studio Installer.png

Prior to the Community Edition, the Visual Studio Express editions were the only Visual Studio distributions that did not require a commercial license. These editions do not ship with the Windows SDK. Anyone installing on Windows 7 and 8 should prefer to install VS 2015 Community. Windows 10 users should prefer VS 2017 Community. When installing on Windows Vista, it is likely easier to allow the DMD installer to install VS 2013 automatically.

An alternative option for those who would prefer not to install Visual Studio is to install both the Microsoft Build Tools and a system-appropriate version of the Windows SDK. When running the DMD installer, it should still detect the Build Tools. If it does not, please report an issue.

When installing DMD via the compressed archive, or when installing the Microsoft tools after DMD, it is necessary to manually edit the DMD configuration file, sc.ini. This can be found in the windows/bin subdirectory of the DMD directory tree (assuming it's installed in C:\D, it would be C:\D\dmd2\windows\bin\sc.ini). Look for the following comment block in the Environment64 section:

; Windows installer replaces the following lines with the actual paths
;VCINSTALLDIR=
;WindowsSdkDir=
;UniversalCRTSdkDir=
;UCRTVersion=

This is a default, unconfigured environment. If the installer had previously detected the Visual Studio installation, the variables would be uncommented and assigned values.

Every Visual Studio and MS Build Tools installation adds a number of shortcuts to the Start menu that will open a command prompt with the proper environment variables configured. To configure these values in sc.ini, open one the appropriate 64-bit command prompt from the Start menu (e.g. "Visual Studio 2017 -> x64 Native Tools Command Prompt for VS 2017", or "Visual Studio 2015 -> VS 2015 x64 Native Build Tools Command Prompt"). From that command prompt, execute each of the following commands, then uncomment the corresponding variable in sc.ini and enter the resulting path.

echo %VCINSTALLDIR%
echo %WindowsSdkDir%
echo %UniversalCRTSdkDir%
echo %UCRTVersion%

Note that the last two are specific to the Windows 10 SDK and will not be present when an older versions of the SDK is installed. In that case, they can be safely ignored.

Once that's accomplished, turn to the next two commented blocks immediately beneath the one you just edited.

; Windows installer uncomments the version detected
;VC2017 LINKCMD=%VCINSTALLDIR%\bin\HostX86\x86\link.exe
;VC2015 LINKCMD=%VCINSTALLDIR%\bin\x86_amd64\link.exe
;VC2013 LINKCMD=%VCINSTALLDIR%\bin\x86_amd64\link.exe
;VC2012 LINKCMD=%VCINSTALLDIR%\bin\x86_amd64\link.exe
;VC2010 LINKCMD=%VCINSTALLDIR%\bin\amd64\link.exe
;VC2008 LINKCMD=%VCINSTALLDIR%\bin\amd64\link.exe

; needed with /DEBUG to find mspdb*.dll (only for VS2012 or later)
;VC2017 PATH=%PATH%;%VCINSTALLDIR%\bin\HostX86\x86
;VC2015 PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\bin
;VC2013 PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\..\Common7\IDE;%VCINSTALLDIR%\bin
;VC2012 PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\..\Common7\IDE

Find the line matching your version of Visual Studio, or the Build Tools, and remove the semi-colon and version number from that line. For example, if you installed the 2015 Build Tools, change the following two lines:

;VC2015 LINKCMD=%VCINSTALLDIR%\bin\x86_amd64\link.exe

;VC2015 PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\bin

To this:

LINKCMD=%VCINSTALLDIR%\bin\x86_amd64\link.exe

PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\bin

This will allow the generation of 64-bit binaries (via the -m64 command line flag) with the MS toolchain. To enable 32-bit binary generation (via the -m32mscoff command line flag), open the appropriate 32-bit (x86) VS command prompt and repeat these steps for the variables in the Environment32mscoff section of sc.ini.

Debian Linux compatible

If you have distribution that's based on APT package manager, you might use APT Repository.

Arch Linux

There are packages in the community repository for dmd, dub, ldc and other D tools. Install them using pacman:

pacman -S dmd

Gentoo Linux

You can use the ebuilds from the dlang overlay like this:

emerge app-portage/layman
layman -f -a dlang
emerge dev-lang/dmd

Note that if you are using Hardened Gentoo, you may need to use a non-hardened linker or specify PIC=1 when compiling Phobos.

Other POSIX compliant

You might try looking for precompiled package for your distribution on http://dlang.org/download.html

If it's isn't there you might try building from source.