Saturday, August 18, 2012

Compiling gcc-4.7.1 on Ubuntu 12.04

I'm working on OpenCog's Cygwin port for my GSoC 2012 project (with help and guidance from my mentors Nil Geisweiller and David Hart). Right now, I'm trying to build MOSES under Cygwin. And, I'm stuck at: Nil found out that the cause of this problem is that std::future isn't defined, it is only declared (based on [1][2][3][4][5]). This seems however to be a problem with Cygwin itself, as it doesn't fully support C++11 yet.
On my request, Nil had a look at gcc-4.7.1 source to check the status of C++11 support in gcc-4.7 (especially std::future as described above). He found out that the macro conditional wrapping the definition of std::future is nearly the same (which would indicate that it would not work), however [1] seems to suggests that it should work with gcc-4.7 So, we agreed that I should try to build gcc-4.7.1 on Cygwin.

But my desperate attempts to build gcc-4.7.1 on Cygwin failed. I even tried getting some help from not-so-active #cygwin ( and someone told me this: But other than this IRC conversation, I could not find much help in Cygwin documentation and on mailing list archives.

So, I thought of building gcc-4.7.1 on Linux first. My intent was to build gcc-4.7.1 in a minimal Ubuntu install (this explains the reason behind using debootstrap chroot below) so that I understand the minimum must-have requirements/dependencies for gcc.

Unless you are running version 12.04 of Ubuntu, please don't blatantly copy/paste commands below (For any other Ubuntu version, please read documentation, linked as References at the end of this post, in detail). Here are the steps I followed to build gcc-4.7.1 on Ubuntu 12.04:

1. Setup Ubuntu-12.04 debootstrap chroot [6]:
sudo debootstrap precise /var/chroot/precise
2. Make chroot usable (and thus useful) [7]:
sudo cp /etc/resolv.conf /var/chroot/precise/etc/resolv.conf
sudo cp /etc/apt/sources.list /var/chroot/precise/etc/apt/
sudo chroot /var/chroot/precise/
echo "export LANG=C" >> /root/.bashrc
source /root/.bashrc
apt-get update
apt-get --no-install-recommends install nano wget
3. Open file /etc/fstab using following command:
nano /etc/fstab
and append following in this file [8]:
/proc /var/chroot/hardy/proc none rbind 0 0
/dev /var/chroot/hardy/dev none rbind 0 0
/sys /var/chroot/hardy/sys none rbind 0 0
/tmp /var/chroot/hardy/tmp none rbind 0 0
/home /var/chroot/hardy/home none rbind 0 0
/media /var/chroot/hardy/media none rbind 0 0
/lib/modules /var/chroot/hardy/lib/modules none rbind 0 0
/var/run/dbus/ /var/chroot/hardy/var/run/dbus/ none rbind 0 0
4. Install build dependencies/prerequisites:
apt-get --no-install-recommends install g++ gawk m4 gcc-multilib

5. Download gcc-4.7.1 inside chroot using 'wget':
cd /root
wget -c
(To choose another version of gcc or another download mirror, goto
I tried a few different approaches to build gcc but got stuck at some errors such as [9] (see also [10][11] for more details and [12] for solution) and build failing inside pbuilder chroot with error (as a solution, I used debootstrap instead as in instructions in this blogpost).

For detailed documentation to install gcc, [13] is the authoritative reference.


1 comment: