Open main menu

Aram's Wiki β

Changes

Linux/amd64 GCC 8.3.0 cross-compiler instructions

2,480 bytes added, 17:12, 13 March 2019
Created page with "== Introduction == We'll build GCC 8.3.0 targeting Linux (Debian 9.8) for amd64. == Create directories == cd $HOME mkdir -p src obj/{binutils-build,gcc-build} x86_64-linu..."
== Introduction ==

We'll build GCC 8.3.0 targeting Linux (Debian 9.8) for amd64.

== Create directories ==

cd $HOME
mkdir -p src obj/{binutils-build,gcc-build} x86_64-linux-gnu/{lib,usr/{include,lib}}

== Get GCC and binutils ==

curl http://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.bz2 | tar -C src xf -
curl http://ftp.gnu.org/gnu/gcc/gcc-8.3.0/gcc-8.3.0.tar.gz | tar -C src xf -

== Download prerequisites ==

cd $HOME/src/gcc-8.3.0
./contrib/download_prerequisites

== Create a sysroot ==

cd $HOME
for d in /lib/ /usr/{include,lib}; do rsync -a debian.local:$d/ x86_64-linux-gnu$d; done

== Build and install binutils ==

cd $HOME/obj/binutils-build
../../src/binutils-2.32/configure --prefix $HOME/xgcc --bindir $HOME/bin --target x86_64-linux-gnu --with-sysroot=$HOME/x86_64-linux-gnu
make -j8 && make install

== Build and install gcc ==

cd $HOME/obj/gcc-build
../../src/gcc-8.3.0/configure --prefix $HOME/xgcc --bindir $HOME/bin --target x86_64-linux-gnu --with-sysroot=$HOME/x86_64-linux-gnu --enable-languages=c --with-gnu-as --with-gnu-ld --disable-multilib
make -j8 && make install

== Test ==

: emerald:tmp; uname -a
Darwin emerald.local 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64
: emerald:tmp;
: emerald:tmp; cc hello.c
: emerald:tmp; ./a.out
Hello, world!
: emerald:tmp;
: emerald:tmp; file a.out
a.out: Mach-O 64-bit executable x86_64
: emerald:tmp;
: emerald:tmp; x86_64-linux-gnu-gcc hello.c
: emerald:tmp; file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, not stripped
: emerald:tmp;
: emerald:tmp; scp a.out debian.local:
a.out 0% 0 0.0KB/s --:-- ETA
a.out 100% 16KB 7.8MB/s 00:00
: emerald:tmp; ssh debian.local ./a.out
Hello, world!
: emerald:tmp; x86_64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=x86_64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/Users/aram/xgcc/libexec/gcc/x86_64-linux-gnu/8.3.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../../src/gcc-8.3.0/configure --prefix /Users/aram/xgcc --bindir /Users/aram/bin --target x86_64-linux-gnu --with-sysroot=/Users/aram/x86_64-linux-gnu --enable-languages=c --with-gnu-as --with-gnu-ld --disable-multilib
Thread model: posix
gcc version 8.3.0 (GCC)
: emerald:tmp;