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: http://pastebin.com/6KCBTr8W. 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 (irc.freenode.net) and someone told me this: http://pastebin.com/TgrWnyfS. 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 http://archive.ubuntu.com/ubuntu/
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 http://www.netgull.com/gcc/releases/gcc-4.7.1/gcc-4.7.1.tar.bz2
(To choose another version of gcc or another download mirror, goto http://gcc.gnu.org/mirrors.html)
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 http://pastebin.com/4NL6RfhY (as a solution, I used debootstrap instead as in instructions in this blogpost).

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

References:
[1] http://scottmeyers.blogspot.fr/2012/04/c11-is-almost-here-for-real.html
[2] http://stackoverflow.com/questions/10209871/c11-stdasync-doesnt-work-in-mingw
[3] http://cygwin.com/ml/cygwin/2010-03/msg00727.html
[4] http://stackoverflow.com/questions/3414834/gcc-stdthread-not-found-in-namespace-std
[5] http://cygwin.1069669.n5.nabble.com/GCC-4-4-0-Can-t-activate-threading-support-td50226.html
[6] https://wiki.ubuntu.com/DebootstrapChroot
[7] https://wiki.ubuntu.com/DebootstrapChroot#Setting_up_your_chroot_with_debootstrap
[8] https://wiki.ubuntu.com/DebootstrapChroot#Getting_stuff%28X/ssh-agent/ect,dbus,mounting%20removables,modprobe,err%20stuff%29_working_automagically
[9] https://bugs.launchpad.net/ubuntu/+source/gcc-4.6/+bug/968766
[10] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52639
[11] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=670164
[12] http://stackoverflow.com/a/10339798
[13] http://gcc.gnu.org/install/

1 comment: