5

Using a Ubuntu 12.04 host, I carefully followed this SO answer here (Recipe for Compiling Binutils and GCC Together) to build GCC and binutils in one tree with all of their dependencies.

Here is the configure line I am doing inside my build directory:

    ../gcc-4.9.0/configure --target=arm-linux-gnueabi --prefix=/home/mint/cross-arm --disable-werror

The Makefile configures correctly and afterwards I run:

    sudo make -j8

I get into the compilation process for some time then eventually it errors out here:

    In file included from ../../../gcc-4.9.0/libgcc/gthr.h:148:0,
             from ../../../gcc-4.9.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
#include <pthread.h>
                 ^
compilation terminated.
make[2]: *** [_gcov_flush.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from ../../../gcc-4.9.0/libgcc/gthr.h:148:0,
             from ../../../gcc-4.9.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
#include <pthread.h>
                 ^
compilation terminated.
make[2]: *** [_gcov_execlp.o] Error 1
In file included from ../../../gcc-4.9.0/libgcc/gthr.h:148:0,
             from ../../../gcc-4.9.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
#include <pthread.h>
                 ^
In file included from ../../../gcc-4.9.0/libgcc/gthr.h:148:0,
             from ../../../gcc-4.9.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
#include <pthread.h>
                 ^
compilation terminated.
make[2]: compilation terminated.
*** [_gcov_fork.o] Error 1
make[2]: *** [_gcov_execl.o] Error 1
In file included from ../../../gcc-4.9.0/libgcc/gthr.h:148:0,
             from ../../../gcc-4.9.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
#include <pthread.h>
                 ^
compilation terminated.
make[2]: *** [_gcov_execle.o] Error 1
make[2]: Leaving directory `/home/mint/Workspaces/src/build/arm-linux-gnueabi/libgcc'
make[1]: *** [all-target-libgcc] Error 2
make[1]: Leaving directory `/home/mint/Workspaces/src/build'
make: *** [all] Error 2

Am I missing a certain dependency that is preventing this build?

P.S. I installed 'build-essential' via apt-get before the build.

Community
  • 1
  • 1
KrizzzyS
  • 53
  • 1
  • 1
  • 6
  • What about letting for example [Buildroot](http://buildroot.uclibc.org/) making this work for you? – yegorich Aug 08 '14 at 12:47
  • Is it pretty painless? – KrizzzyS Aug 11 '14 at 03:35
  • So far I didn't experienced any problems. BR provides several ways to get a toolcahin. Just read [this](http://nightly.buildroot.org/manual.html#_cross_compilation_toolchain) portion of documentation and try the way, that best suits your needs. In the most cases I use external toolchain, it saves time, when I need to recompile the whole rootfs. – yegorich Aug 11 '14 at 07:27
  • how will anyone know know to maintain buildroot or replace it without learning. Its like not going to math class because calculators exist... – old_timer May 01 '20 at 18:51

1 Answers1

0

The error suggests some issue with the C library.

For building the GCC compiler, you need prebuilt binutils + prebuilt C library.

In case of cross compiler, one possible route is :

  1. Ensure that you have prebuilt binutils (cross compile build)
  2. Cross compile GCC : Add Configure option --without-headers. Now compile (see make targets in the link below)
  3. Compile your C library and point to it when compiling your program for the target

See some instructions for cross-compiling gcc here GCC Cross Compiling. Then "install" the appropriate C library (glibc / newlib).

Also, (if you are not already doing it) it may be worthwhile to ensure that the --prefix for bintutils and the gcc cross compile build are the same location.

Cherry Vanc
  • 781
  • 1
  • 4
  • 19
  • If you take a look at the linked SO answer, I have symlinked all of GCC's dependencies inside the gcc-4.9.0/ dir, I run ./configure like shown above and what I expect is everything to be built with these options. Is this not a recommended way to do this? – KrizzzyS Aug 08 '14 at 00:02
  • The SO answer does not directly relate with a cross-compiler build. Although keep in mind that building the binuitls + gcc in a common dir source tree is orthogonal to whether you are building a cross compiler or not. The problem at hand is because of another dependency of the whole cross-compilation setup = which is C library. – Cherry Vanc Aug 08 '14 at 00:17
  • I see. I've read up on the link you provided. If I compiled as specified, it would return a naked compiler where a simple import of stdio.h would crash it. How would I install the C library post compilation? – KrizzzyS Aug 08 '14 at 00:27
  • Yes, that's right. Now for the C library, you can either use newlib/glibc. Configuring and compiling them should be very straightforward. Its been a while since I did a cross compiler build, so cannot give you the configure command etc right away. – Cherry Vanc Aug 08 '14 at 01:00
  • 1
    I followed directions and after installing binutils, gcc fails with the same pthread error on `make all-target-libgcc`. – KrizzzyS Aug 08 '14 at 02:36
  • 4
    Is there a reason why you have chosen to not use disable-threads for GCC configure ? – Cherry Vanc Aug 08 '14 at 17:51
  • I had no clue that option existed. I'll have to try it. – KrizzzyS Aug 09 '14 at 14:48