Thursday, September 22, 2011

Building the Go gcc Compiler on Ubuntu 11.04

I recently built the Go gcc compiler on Ubunutu 11.04 and the initial build took a couple of days with a lot of incredible help from Ian Lance Taylor of the Go development team via the golang-nuts group. It appears that Debian has changed a lot of things since the instructions on golang.org were written last year.

After figuring out everything on my laptop, I installed Ubuntu 11.04 fresh on another system. There were a couple of hiccups, like I had not installed flex and once I had I did not realize that it needed a fresh directory or the build would fail in a new and different way.

The steps below should allow you to build the compiler. I would love to see someone duplicate the results.

Prerequisites


sudo apt-get install bison gawk gcc libc6-dev libc6-dev-i386 make binutils-dev texinfo flex libmpc-dev cvs subversion


cd /usr/lib64
sudo ln -s /usr/lib/x86_64-linux-gnu/libc.so libc.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libpthread.so libpthread.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libdl.so libdl.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libm.so libm.so
sudo ln -s /usr/local/lib64/libgo.so.0 libgo.so.0

Not A Prerequisite But Helpful


sudo apt-get install apt-file

If you receive an error that the process cannot find a file, this will allow you to determine in which package it resides.

Build binutils


Note that the enable-gold switch is different from what is on golang.org.

cd ~
cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login
[password is "anoncvs"]
cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co binutils
mkdir binutils-objdir
cd binutils-objdir
../src/configure --enable-gold=default --prefix=/opt/gold
make
sudo make install

Build gccgo


cd ~
svn checkout svn://gcc.gnu.org/svn/gcc/branches/gccgo gccgo
mkdir objdir
cd objdir
../gccgo/configure --enable-languages=c,c++,go --with-ld=/opt/gold/bin/ld
make
make install

Runtime Env


gccgo -version

There will be a lot of information, but you only need these two elements.
Target: x86_64-unknown-linux-gnu
gcc version 4.7.0 20110520 (experimental) (GCC)


export LD_LIBRARY_PATH=/usr/lib/gcc/MACHINE/VERSION
where MACHINE is the string after Target
and VERSION is the number after version

LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0

1 comment:

  1. In order to get the build to work I had to do two things:

    A)include "--diable-bootstrap" as part of the gccgo configure step.
    B) "sudo make install" as part of the last step.

    One last thing, I had to reboot as I couldn't remember the commmand to get the linker to find new .so files in order to link the simple hello world example.

    ReplyDelete