Building GCC inside a chroot from source

chrootdevelopmentgcclibraries

In a previous question I asked about creating a chroot that simulates my embedded device environment. It was suggested that I build from source GCC and binutils first inside my chroot. To attempt this I copied the version of libc and gcc binary on my host machine to the chroot. I then wrote a simple hello world program to a file test.c and tried to build in my chroot as follows

  phil@phil-desktop:/usr$ sudo chroot /usr/embedded_chroot1/
  bash-4.2# gcc test.c 
  gcc: error trying to exec 'cc1': execvp: No such file or directory

I am not too sure what is going on here with this error. I have copied the gcc binary and libc to my chroot so why am I unable to compile? Must I copy all system source and header files into my chroot also?? I think I have a conceptual misunderstanding with the whole process of using a chroot.

Best Answer

The gcc build has the ability to bootstrap itself without any existing compiler on the system. You should be able to download and unpack gcc, and build it inside your chroot without having to copy anything from outside. It has been a while since I've done this, but I remember it was reasonably painless.

Look at the build instructions for gcc, which detail this process. You will want to build a native compiler, and all the steps should be performed inside your chroot, so that gcc will be built to match that system.

Related Question