10‐003. Build Cross Compiler - skybonep/fishboneOS GitHub Wiki
We cannot use a normal compiler to compile our code because it will link against libraries on the development machine. Therefore, we need to build our own compiler to compile our pure code (i686-elf).
I am building the cross-compiler on a Linux Ubuntu machine.
Download binutils 2.45.1 from https://ftp.gnu.org/gnu/binutils/
Download GCC 15.2.0 from https://ftp.gnu.org/gnu/gcc/
Linux terminal:
sudo apt-get install libgmp3-dev libmpfr-dev libmpc-dev
export PREFIX="$HOME/opt/cross"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"
# Build binutils
cd $SRC_DIR/src
mkdir build-binutils
cd build-binutils
../binutils-2.45.1/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make
make install
# Build gcc
cd $SRC_DIR/src
# The $PREFIX/bin dir _must_ be in the PATH. We did that above.
which -- $TARGET-as || echo $TARGET-as is not in the PATH
mkdir build-gcc
cd build-gcc
../gcc-15.2.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers --disable-hosted-libstdcxx
make all-gcc
make all-target-libgcc
make all-target-libstdc++-v3
make install-gcc
make install-target-libgcc
make install-target-libstdc++-v3
I haven't built a binary in Linux for a very long time — it brings back memories of watching the terminal scroll by. :)
We can execute it with:
~/opt/cross/bin/i686-elf-gcc --version
Created: 20251225