Skip to content

Instantly share code, notes, and snippets.

@xxuejie
Forked from vlad-ivanov-name/build-gcc.md
Last active October 4, 2019 20:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xxuejie/354316cada4bb0d3430df5e83dd103d3 to your computer and use it in GitHub Desktop.
Save xxuejie/354316cada4bb0d3430df5e83dd103d3 to your computer and use it in GitHub Desktop.
build cross riscv32imac gcc with newlib

Set environment variables

export TARGET=riscv32-unknown-elf
export PREFIX=/work/public/$TARGET
export PATH=$PATH:$PREFIX/bin

Build binutils

mkdir build-binutils
cd build-binutils
CC_FOR_TARGET=riscv32-unknown-elf-gcc ../binutils-source/configure --target=$TARGET --prefix=$PREFIX
make all
make install

Prerequisite libs

cd gcc-source
bash ./contrib/download_prerequisites
cd ..

prerequisite libs (GMP/MPFR/MPC), put them into gcc director, and link statically.

If not, the system gmp/mpft/mpc libraries will be used, and linked dynamically.

http://advogato.org/person/redi/diary/253.html

Build gcc

mkdir build-gcc
cd build-gcc
../gcc-source/configure --target=$TARGET --prefix=$PREFIX --without-header --with-newlib --with-gnu-as --with-gnu-ld --enable-lto --enable-linker-build-id --disable-libmudflap --disable-libgomp --disable-libssp --disable-libstdcxx-pch --enable-multiarch --disable-multilib --enable-languages=c,c++ --with-headers=../newlib-source/newlib/libc/include --disable-shared
make
make install

Build newlib

mkdir build-newlib
cd build-newlib
../newlib-source/configure --target=$TARGET --prefix=$PREFIX
make -j8
make install

Build GCC again with newlib

cd build-gcc
make -j8
make install

Build GDB

mkdir build-gdb
cd build-gdb
../gdb-source/configure --target=$TARGET --prefix=$PREFIX --enable-interwork

Errors

checking for the value of EOF... configure: error: computing EOF failed

--with-headers=../newlib-source/newlib/libc/include

error while loading shared libraries: libmpc.so.2

Please refer to step 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment