Workaround: compiling GCC 3.0 as a cross-compiler under Linux
John Zaitseff
J.Zaitseff@zap.org.au
Thu Nov 15 22:47:00 GMT 2001
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
A number of people have previously queried compiling GCC 3.0 as a
cross-compiler for embedded systems under Linux. These people have had
problems in doing so, with apparently no answers to their queries.
I also have had problems compiling GCC 3.0.2 as a cross-compiler (in my
case, for arm-elf) under Linux. I have found a suitable workaround, which
others having the same problems may like to know. It probably would be
good if someone got around to FIXING the problems as well...
1. Download and unpack the GCC sources as per the standard instructions
(I'll use /usr/local/src/gcc-3.0.2 in this example). Also create a build
directory---I'll use /tmp/build/gcc-3.0.2.
2. You need to download and unpack the newlib distribution (currently
newlib-1.9.0.tar.gz from ftp://sources.redhat.com/pub/newlib) when
compiling GCC for an embedded system. The GCC installation documentation
states that you need "--with-newlib" when configuring GCC, but does NOT
state that you actually need the newlib distribution present and unpacked,
at least as far as I can tell! I'll use /usr/local/src/newlib-1.9.0 in
this example.
3. Assuming that you have already compiled the binutils package for arm-elf
and installed it in /usr/local/bin, /usr/local/arm-elf, etc, do the
following AS ROOT:
# cd /usr/local/arm-elf
# mkdir sys-include
# ln -s sys-include include
# chmod o+w sys-include
# cd /usr/local/lib
# mkdir -p gcc-lib/arm-elf
# chmod o+w gcc-lib/arm-elf
The reason for the world-writable sys-include directory (a VERY bad idea in
general) is that GCC's "configure" will copy files from the newlib
distribution into this directory during configuration.
The reason for the world-writable gcc-lib/arm-elf directory (also a bad
idea) is that GCC's Makefile will copy files there during "make all".
The reason for the symbolic link /usr/local/arm-elf/include -> sys-include
is that compiling libiberty (part of GCC) will fail during "make all" if it
is not present.
4. As an ordinary user, issue the following command (with appropriate
substitutions for your own set-ups, of course):
$ cd /tmp/build/gcc-3.0.2
$ /usr/local/src/gcc-3.0.2/configure --target=arm-elf --with-newlib \
--with-headers=/usr/local/src/newlib-1.9.0/newlib/libc/include
5. Compile GCC:
$ make all
6. Now you can install the cross-compiler, and remove the world-writable
permission from those directories listed above:
# make install
# chmod o-w /usr/local/arm-elf/sys-include
# chmod o-w /usr/local/lib/gcc-lib/arm-elf
# chown -R root:root /usr/local/arm-elf/sys-include
# chown -R root:root /usr/local/lib/gcc-lib/arm-elf
7. NOW you can go ahead and compile newlib as per instructions...
This workaround highlights the following bugs:
1. GCC's "configure" expects write-access to system directories (in this
case /usr/local/arm-elf/sys-include) to copy header files.
2. GCC's Makefile expects write-access to system directories (in this case
/usr/local/lib/gcc-lib/arm-elf/3.0.2/include) to create "fixed" header
files.
3. Libiberty's Makefile (in .../libiberty, part of GCC) uses "include"
instead of "sys-include" when compiling the cross-compiled version of its
library. I am not sure if the link created in step 3 needs to be kept
after GCC's installation.
I hope this helps other people. Please send any replies directly to my
e-mail address (J.Zaitseff@zap.org.au) as I am not subscribed to the
gcc-help mailing list.
Yours truly,
John Zaitseff
- --
John Zaitseff ,--_|\ The ZAP Group
Phone: +61 2 9543 6448 / \ Sydney, Australia
E-mail: J.Zaitseff@zap.org.au \_,--._* http://www.zap.org.au/
Finger: john@zap.org.au v
GnuPG fingerprint: 8FD2 8962 7768 2546 FE07 DE7C 61A8 4486 C9A6 69B0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iEYEARECAAYFAjv9e5gACgkQYahEhsmmabCusgCdF7ZE0O+E0InMoES3zwH1J/Pd
SZ4AnRmHHew14RG4Fq+eQz0ID/Ch7QKo
=wv7F
-----END PGP SIGNATURE-----
More information about the Gcc-help
mailing list