LDC on Windows with MinGW
Warning: Both LLVM and LDC haven't been overly well tested on Windows / MinGW. Their status is still considered to be experimental on this platform.
This guide is intentionally kept simple and basic and to the minimum needed to get things working, written in the hope that those who are less experienced and not too familiar with *nix-isms can follow along. Commands are formatted as bold, directories in a monospaced font, and things to be replaced by whatever they may be on your machine will be in <…>.
You will need a number of tools from the MinGW project, they are linked directly in the instructions below (up to date as of 05.10.2009). Alternatively, you can point your browser to the project's sourceforge repository and download them from there.
It is assumed that you have already installed the following applications:
- Subversion (source control system system used by LLVM and tango)
- Mercurial (source control system used by LDC)
- cmake 2.6+ (2.4 should actually work, with a warning)
You can either let the MinGW installer fetch the files for you, or download them manually to the same directory you copied the installer to, as you prefer.
Run the installer. All you will need is the minimal install, and g++ for LDC.
If the installer doesn't work, no problem - just grab the packages listed above and unzip them into C:\MinGW (so that you'll have C:\MinGW\bin, C:\MinGW\include etc.). There are a lot of programs that support .tar.gz on Windows; 7-zip is one of them.
(You can also choose another installation directory for MinGW, but it should not contain spaces.)
Although there are alternatives to the official MinGW package (eg. nuwen.net) which might be somewhat easier to install, come with more recent gcc versions and bison, flex, regex and other useful tools out of the box, only use these if you know what you are doing. You will still need to set up MSYS to compile LDC, and you might run into unexpected problems which are harder to work around than using the official packages in the first place.
Run the MSYS 1.0.11 Base System installer. Note that spaces in LDC's path are problematic right now, so you should keep MSYS' installation directory spaceless.
In the console window that will pop up, choose to run the post-install script, confirm that you have MinGW installed and enter its directory (which will probably be c:/mingw, with a Unix-style forward slash).
Run the installer for the MSYS Supplementary Tools (also known as MSYS Developer's Tool Kit; it contains autoconf, automake, libtool, perl, etc.).
You can also check if your MSYS/MinGW integration is set up correctly here. Try gcc . If you get a "command not found" error, see if you have a <msys>/etc/fstab file in place, and if your MinGW installation dir is listed in it. If not, you should edit the file to have a line looking like c:/mingw /mingw, the c:/mingw depending on where you installed MinGW to, of course. You will have to exit from MSYS and restart it afterwards.
Under Vista and 7, make sure that you run MSYS as an administrator.
It is recommended to get the llvm sources via subversion and copy them to your home directory in MSYS (<your msys dir>/home/<username>/llvm/). The release_26 branch should work. You will still need to get the sources and compile yourself though, the downloadable binary distribution available on the LLVM website only contains executables while for LDC we need libraries.
Get into MSYS, cd llvm and do a ./configure --enable-optimized and make . This will take some time. Once it has finished the resulting binaries will be in ./Release/. (If you want, you can also put the build files in a separate directory, e.g. by doing mkdir build; cd build; ../configure … instead.)
Do a make install. This will spawn an error because msys is missing some packages which are needed to generate llvm's documentation. No big deal, don't worry about it. (There used to be a bug which caused the binaries to be installed without the .exe suffix, but it seems to have been fixed by now.)
Note: Apparently, $HOME points to the Windows user directory in some versions of MSYS. If this is the case for your installation, you have to adjust the paths mentioned in this document accordingly.
Get the sources for LDC with the following Mercurial command:
hg clone http://hg.dsource.org/projects/ldc ldc
Copy the sources to <msys>/home/<username>/ldc/.
Before running cmake, you need to install libconfig: Download the source from the link above and untar/ungzip it. Change directories to the libconfig directory and use ./configure --prefix=/mingw so that the library can be found properly afterwards. make and make install. (If you get errors about undefined references to symbols starting with __imp_ you can ln -s /mingw/lib/libconfig++.a to /mingw/lib/libconfig++.dll.a. It seems as though the dll file needs to be found before the regular .a file).
You will also want to have pkg-config available for CMake-Gui. Download the glib2 "binaries" file and pkg-config "tool binaries" from the GTK+ for Windows site to your MinGW directory and unzip them. Then close and reopen the MSYS terminal, if you had it open.
LDC uses CMake to generate its build files: Start the CMake-GUI (use "cmake-gui.exe ./" to auto fill in some proper values, if you like), select ldc's source directory as source and a directory of your choice as build directory, and click the 'Configure' button. Confirm creating the selected build directory if it is not already present.
You will now be asked to select the type of build system you want to use. MSYS, MinGW and Codeblocks makefiles at least are supposed to work, make your choice or even test one of the others if you feel daring. We assume MSYS. If this is the first time you are using CMake with the MinGW compilers you might will have to do the compiler setup here too. Select your MinGW's gcc and g++ executables (C <your MinGW dir>/bin/gcc.exe, C++ <your MinGW dir>/bin/g++.exe).
If your LLVM binaries are not on your system's path an error message will pop up now. Just confirm, set LLVM_INSTDIR to your LLVM install path (<msys>/1.0/local). Sometimes, CMake also fails to find LLVM's Config/config.h, in which case you just have to specify the LLVM_CONFIG_FILE_PATH manually. You may have to set CMAKE_CXX_FLAGS to -DLLVM_REV=llvmrevisionno (e.g.-DLLVM_REV=84989 for LLVM 2.6) too. Click on show advanced values checkbox to see CMAKE_CXX_FLAGS.
Check the settings and 'Configure' until none of the entries have a red background anymore. The 'Generate' button should be activated now, click it. You can then close the GUI.
Only use cmake and build ldc from within the source dir (ie. $home/ldc) for now. Start MSYS, cd to whatever you chose as your build directory in cmake (eg. for $home/ldc cd $home/ldc ), and then run make.
If you have selected MinGW or Codeblocks makefiles you should make sure <your MinGW dir>\bin is on your system's path, and you will need to extract mingw32-make into your MinGW directory. Enter a windows console in your build dir and run mingw32-make or fire up Codeblocks, open LDC's project file, and build.
When the build has finished you should have a ldc binary in <your build dir>/bin/ . Try executing it, it should display version information and a list of options.
Now either add this directory to the path (export PATH=$PATH:´pwd´/bin) or make install and add the bin directory of the installation to the path. If you don't want to retype this line every time you start msys, add the export PATH=… command to <msys>/etc/profile or simply add the bin directory to your system (Windows) path.
LDC solely supports the Tango runtime for now. To install it, change to your home directory in MSYS and fetch the sources from SVN:
svn co http://svn.dsource.org/projects/tango/trunk tango
If you have selected to build LDC for D2 (which is in an even more experimental state than LDC on Windows is anyway) you will need druntime instead of Tango, so replace tango with druntime in the command above.
To install Tango, first issue ln -s /mingw/bin/gcc.exe /mingw/bin/cc.exe from inside MSYS because the tango build script excepts to find a cc in the $PATH. Then, change to the tango/build directory and simply issue export DC=<path_to_ldc_exe>/ldc ./build.sh to build tango and install its core library. The script will output some instructions on how to install the second part of Tango, the user libraries, after it completes.
Go and compile something with ldc.
If you get a failure related to ldc's configuration file not being found, then copy the ldc.conf file from ldc/bin/ldc.conf to your home directory cp $HOME/ldc/bin/ldc.conf $HOME.
Known LDC bugs on Windows
- Exception handling doesn't work yet.
- Calling conventions might not work as expected.