Building under Windows

From D Wiki
Revision as of 04:40, 22 August 2016 by Greenify (talk | contribs) (Moved from Starting_as_a_Contributor)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Prerequisites

On Windows, you will need Git for Windows, the DigitalMars C++ compiler, and, for 64-bit or 32-bit COFF builds, the Microsoft Windows SDK.

Building D

The following instructions work for win32. May or may not work with win64. This scheme is a suggestion. These instructions should work when building from a clean repository, however, this repository contains autogenerated code that may be left behind after switching branches so running a git clean after switching branches is a good idea:

git clean -xfd

Assuming your sources are checked out C:\D, and that make from digital mars is in your path, you can do the following to build them:

set DM_HOME=C:\D
cd %DM_HOME%\dmd2\src\dmd\src
make -fwin32.mak release

From there, it is suggested to move the built binaries into your %DM_HOME%\windows\bin directory, and add that to your path:

copy *.exe %DM_HOME%\dmd2\windows\bin
set path=%path%;%DM_HOME%\dmd2\windows\bin

From there, you have to create a sc.ini in your DMD.exe directory. It is suggested to just copy paste the one provided in the packaged 2.110.0, instead of writing your own.

Now build druntime:

cd %DM_HOME%\dmd2\src\druntime
make -fwin32.mak

And phobos:

cd %DM_HOME%\dmd2\src\phobos
make -fwin32.mak

You should copy the phobos lib into your windows\lib folder:

copy phobos.lib %DM_HOME%\dmd2\windows\lib

Optionally, you can build rdmd from source if you have checked out tools in your sources:

cd %DM_HOME%\dmd2\src\tools
make -fwin32.mak rdmd.exe
copy *.exe %DM_HOME%\dmd2\windows\bin

The last step is getting the additional libs. curl for D2 can be found at the bottom of the download section of dlang.org: [download].

Additional libs that are necessary can simply be copy pasted from the 2.110.0 package (without overwriting your phobos.lib)

The very last step is to verify that everything works by unittesting phobos:

cd %DM_HOME%\dmd2\src\phobos
make -fwin32.mak unittest

Common Windows issues

Missing MASM386

If when building druntime you get errors about missing MASM386, it's due to a required assembling of a file called minit.asm. However the druntime repository includes a prebuilt minit.obj file so you shouldn't need to assemble it again. As a workaround for the make error create an empty masm386.bat file and put it in a directory that's in your PATH.

It's also recommended that you use the cmd.exe terminal. Others, like PowerShell, are known to experience issues with legacy tools.

Intermediate files lead to several errors

The three main components (dmd, druntime, phobos) should always be built together with matching versions. The intermediate files generated by a previous build can lead to a failure so it's advisable to run

make -fwin32.mak clean

on each component before starting the process.