Table of Contents
GDC Installation
This page tells you how to compile GDC from sources and also install compiled Tango sources.
It's designed to be mostly copy&paste.
For MacOS users: A patched Apple GCC is desirable to get better support (unversial binaries etc.) instead of patching the ordinary GCC as it is shown here. Prebuild packages are available.
GDC Installation from binary distribution
The binary distribution of GDC can be retrieved at SourceForge. Chose the appropriate file according to what operating system you run. The archives are all bzipped, which means you need either bunzip2, or another program that supports the format.
All archives have a common structure according to the directories you find in /usr on a common Unix-like operating system:
- gdc/
- bin/
- include/
- lib/
- libexec/
- man/
- share/
The easiest way to achieve a correct installation of GDC is to just copy the whole content of the gdc/ directory into a directory of your choice (/usr/local or /usr, if you have root access to your development/evaluation machine).
If you feel like doing a special installation, be aware of the fact that this could lead to a corrupt or not fully functional installation.
GDC Installation from source
These instructions apply for the SourceForge Subversion GDC repository. In case you already have GDC installed in an appropriate version, you can skip this section.
Prerequisites
You need at least these programs installed for the next steps. Most of them are probably already installed.
- curl or wget
- bzip2
- tar
- patch
- svn (subversion)
- c++ (or g++; you may want to do "ln -s /usr/bin/g++ /usr/bin/c++")
Getting GCC
Get the GCC sources from http://gcc.gnu.org/. You need at least the gcc-core-x.x.x file, or the gcc-x.x.x file if you want the full GCC collection. For this document, it is assumed that you have gcc-core-4.1.2.tar.bz2 and gcc-g++-4.1.2.tar.bz2.
curl ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.1.2/gcc-core-4.1.2.tar.bz2 -o gcc-core-4.1.2.tar.bz2 curl ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.1.2/gcc-g++-4.1.2.tar.bz2 -o gcc-g++-4.1.2.tar.bz2
Note: There is an experimental gdc branch for gcc-4.3.1 and also howto.
Getting GDC
If you want the latest D features, use the trunk directory. You will find the latest branch in the branches directory of your GDC sources, but it may be outdated.
For trunk you would do
svn co https://dgcc.svn.sourceforge.net/svnroot/dgcc/trunk/d
which creates the d directory.
Compiling GDC
This will be shown keeping separate directories for the sources and the compiled binaries.
1. Extract the GCC sources to an empty directory
mkdir gdc-sf cd gdc-sf tar xjf ../gcc-core-4.1.2.tar.bz2 tar xjf ../gcc-g++-4.1.2.tar.bz2
on Macintosh 10.5 you have to change "--strip-underscores" to "--strip-underscore" in "gcc-4.1.2/libstdc++-v3/scripts/make_exports.pl".
2. Copy the GDC sources to the GCC directory, and run the setup script.
cd gcc-4.1.2/gcc cp -R ../../../d . cd .. gcc/d/setup-gcc.sh
3. Create a new empty directory for building.
cd .. mkdir build cd build
4. Configure, make, make install.
Don't forget to enable all languages you want to use. (add --disable-multilib on x64 systems)
../gcc-4.1.2/configure --enable-languages=c,c++,d --enable-static --disable-shared --prefix=$HOME/d/gdc024 make sudo make install
Notes:
- "--prefix" is optional and points to the place where all GDC files will go on "make install".
- "--enable-static --disable-shared" are optional but may prevent some errors like "version `GCC_4.2.0' not found".
- "c,c++", is optional, you can drop it to speed up compile times.
On Macintosh you might want to replace the previous commands with
../gcc-4.1.2/configure --prefix=$HOME/d/gdc024 --disable-nls --disable-multilib --enable-languages=c,c++,d make sudo make install
5. Test
export PATH=$HOME/d/gdc024/bin:$PATH export LD_LIBRARY_PATH=$HOME/d/gdc024/lib:$LD_LIBRARY_PATH gdc --version
You might want to put the export lines into your ~/.bash_profile file.
Install Tango
When you have compiled the Tango library (steps 1 and 2) you can add the Tango files to your GDC installation.
It is assumed that GDC was installed in ~/d/gdc024 and Tango in ~/trunk. Change the paths as necessary.
export TRUNK=~/trunk export GDC=~/d/gdc024 cd $(GDC) rm -rf include/d/4.1.2/object.d rm -rf include/d/4.1.2/std/ rm -rf lib/libgphobos.a cd $(TANGO) cp -r object.d std/ tango/ $(GDC)/include/d/4.1.2/ cp -r lib/libgphobos.a lib/libgtango.a $(GDC)/lib/
Now create some Hello World program in a file called main.d:
import tango.io.Stdout; void main() { Stdout("Hello World").newline; }
And try to compile it:
gdc main.d -o main -fversion=Posix -fversion=Tango -I$(GDC)/include/d/4.1.2 -L$(GDC)/lib -lgtango
Note:
- If GDC was not found, you have to extend your PATH variable.