How to build a cross gcc from the very beginning?

Franklin franklin@goodhorse.idv.tw
Mon Jan 3 05:27:00 GMT 2005


Hi list, Happy New Year!

I've been confused for a while about building a cross gcc from nothing.
The target platform of this requested gcc and glibc is mipsel-linux.

I googled a lot and had a conclusion.  It seems that I need to build a (minimal) cross gcc first, and use this gcc to build glibc, then build a complete cross gcc.  (Is that right?)

So I built binutils-2.15 first and installed into /usr/local/mipsel/target first.
Then I configured gcc as follows:

<shell command>
../gcc-3.2.3/configure --prefix=/usr/local/mipsel/target \
--host=i586-mandrake-linux-gnu --target=mipsel-linux --enable-languages=c \
--with-cpu=mipsel-linux --disable-threads
</shell command>

(I used gcc-3.2.3 because I need to compile linux-2.4.18 for mips...
 It seemed not a good idea to compile with gcc-3.3 or above.)

I used --disable-threads because it will ask for pthread.h, and at that time glibc had not been built yet.

After successfully configured, I typed:

make bootstrap

It compiled for a while and stopped with the following error:

<error messages>
./xgcc -B./ -B/usr/local/mipsel/target/mipsel-linux/bin/ -isystem \
/usr/local/mipsel/target/mipsel-linux/include -isystem \
/usr/local/mipsel/target/mipsel-linux/sys-include -O2  -DIN_GCC -DCROSS_COMPILE  \
 -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -isystem ./include \
 -fPIC -g  -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -Dinhibit_libc -shared -nodefaultlibs \
-Wl,--soname=libgcc_s.so.1 -Wl,--version-script=libgcc/./libgcc.map -o libgcc_s.so.1  \
libgcc/./_muldi3.o libgcc/./_negdi2.o libgcc/./_lshrdi3.o libgcc/./_ashldi3.o \
(... with a lot of .o files...) \
libgcc/./unwind-sjlj.o -lc && rm -f libgcc_s.so && ln -s libgcc_s.so.1 libgcc_s.so

/usr/local/mipsel/target/mipsel-linux/bin/ld: crti.o: No such file: No such file or directory
collect2: ld returned 1 exit status
</error messages>

It asked for crti.o... where should I find it? It seemed to be in glibc.

Then I tried to add --disable-shared when configuring gcc, because I thought that
it failed while linking libgcc_s.so.

However, a lot of errors occurred while compiling:

<error messages>
make[2]: Entering directory `/usr/local/src/mipsel/gcc-3.2.3-build/gcc'
stage1/xgcc -Bstage1/ -B/usr/local/mipsel/target/mipsel-linux/bin/ -c -DIN_GCC -DCROSS_COMPILE   -g -O2 -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wtraditional -pedantic -Wno-long-long  -DHAVE_CONFIG_H -DGENERATOR_FILE    -I. -I. -I../../gcc-3.2.3/gcc -I../../gcc-3.2.3/gcc/. -I../../gcc-3.2.3/gcc/config -I../../gcc-3.2.3/gcc/../include ../../gcc-3.2.3/gcc/gengenrtl.c -o gengenrtl.o
In file included from ../../gcc-3.2.3/gcc/gengenrtl.c:23:
../../gcc-3.2.3/gcc/system.h:50:19: stdio.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:112:23: sys/types.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:114:19: errno.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:121:21: string.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:122:22: strings.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:134:21: stdlib.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:157:21: unistd.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:161:24: sys/param.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:200:23: sys/time.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:201:19: time.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:213:20: fcntl.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:251:22: sys/wait.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:318:20: malloc.h: No such file or directory
../../gcc-3.2.3/gcc/system.h:387:23: sys/stat.h: No such file or directory
In file included from ../../gcc-3.2.3/gcc/gengenrtl.c:26:
../../gcc-3.2.3/gcc/rtl.h:1867: syntax error before '*' token
../../gcc-3.2.3/gcc/rtl.h:1867: warning: function declaration isn't a prototype
../../gcc-3.2.3/gcc/rtl.h:1972: syntax error before "FILE"
../../gcc-3.2.3/gcc/rtl.h:1972: warning: function declaration isn't a prototype
../../gcc-3.2.3/gcc/gengenrtl.c: In function `type_from_format':
../../gcc-3.2.3/gcc/gengenrtl.c:149: warning: implicit declaration of function `abort'
../../gcc-3.2.3/gcc/gengenrtl.c: In function `special_format':
../../gcc-3.2.3/gcc/gengenrtl.c:194: warning: implicit declaration of function `strchr'
../../gcc-3.2.3/gcc/gengenrtl.c: In function `special_rtx':
../../gcc-3.2.3/gcc/gengenrtl.c:208: warning: implicit declaration of function `strcmp'
../../gcc-3.2.3/gcc/gengenrtl.c: In function `gendecl':
../../gcc-3.2.3/gcc/gengenrtl.c:247: warning: implicit declaration of function `printf'
../../gcc-3.2.3/gcc/gengenrtl.c:255: warning: implicit declaration of function `strlen'
../../gcc-3.2.3/gcc/gengenrtl.c: In function `genmacro':
../../gcc-3.2.3/gcc/gengenrtl.c:295: warning: implicit declaration of function `puts'
../../gcc-3.2.3/gcc/gengenrtl.c: In function `gendef':
../../gcc-3.2.3/gcc/gengenrtl.c:316: warning: function `puts' was previously declared within a block
../../gcc-3.2.3/gcc/gengenrtl.c: In function `genlegend':
../../gcc-3.2.3/gcc/gengenrtl.c:345: warning: function `puts' was previously declared within a block
../../gcc-3.2.3/gcc/gengenrtl.c: In function `genheader':
../../gcc-3.2.3/gcc/gengenrtl.c:356: warning: function `puts' was previously declared within a block
../../gcc-3.2.3/gcc/gengenrtl.c:362: warning: implicit declaration of function `putchar'
../../gcc-3.2.3/gcc/gengenrtl.c: In function `gencode':
../../gcc-3.2.3/gcc/gengenrtl.c:378: warning: function `puts' was previously declared within a block
../../gcc-3.2.3/gcc/gengenrtl.c: In function `main':
../../gcc-3.2.3/gcc/gengenrtl.c:411: warning: implicit declaration of function `ferror'
../../gcc-3.2.3/gcc/gengenrtl.c:411: `stdout' undeclared (first use in this function)
../../gcc-3.2.3/gcc/gengenrtl.c:411: (Each undeclared identifier is reported only once
../../gcc-3.2.3/gcc/gengenrtl.c:411: for each function it appears in.)
../../gcc-3.2.3/gcc/gengenrtl.c:411: warning: implicit declaration of function `fflush'
../../gcc-3.2.3/gcc/gengenrtl.c:411: warning: implicit declaration of function `fclose'
make[2]: *** [gengenrtl.o] Error 1
</error messages>

If I had used --disable-shared and used `make` instead of `make bootstrap`, 
thanks God it could be compiled successfully.

But then... oh no, it failed to build glibc because it couldn't find libgcc_eh!

Could anybody, pretty please, tell me what and how to do, in what sequences, 
to build the whole thing?

Thanks very much for helping me.


Best Regards,
Frank Weng (a.k.a. Franklin)



More information about the Gcc-help mailing list