Skip to content

Instantly share code, notes, and snippets.

@ricardocosme
Created February 8, 2021 21:19
Show Gist options
  • Save ricardocosme/5ec8ad05b5f4adb66464a146dcc41545 to your computer and use it in GitHub Desktop.
Save ricardocosme/5ec8ad05b5f4adb66464a146dcc41545 to your computer and use it in GitHub Desktop.
avr-gcc 10.2 with libstdc++ using the freestanding implementation
#This is a step-by-step guide to build the avr-gcc 10.2 with the
#libstdc++ using the freestanding implementation[1].
#
#Don't expect a robust script without boilerplates or something coded
#to be resilient. This is only a short register of what I need to
#obtain the compiler in this mode.
#
#[1] https://timsong-cpp.github.io/cppwp/n4861/compliance
wget https://ftp.gnu.org/gnu/binutils/binutils-2.36.tar.gz
tar zxf binutils-2.36.tar.gz
cd binutils-2.36
mkdir obj
cd obj
../configure --prefix=$PREFIX --target=avr --disable-nls
make -j16
make install
cd ../../
export PATH=$PREFIX/bin:$PATH
wget https://bigsearcher.com/mirrors/gcc/releases/gcc-10.2.0/gcc-10.2.0.tar.gz
tar zxf gcc-10.2.0.tar.gz
cd gcc-10.2.0
mkdir obj
cd obj
../configure --prefix=$PREFIX --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2
make -j16
make installl
cd ../../
wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-2.0.0.tar.bz2
tar jxf avr-libc-2.0.0.tar.bz2
cd avr-libc-2.0.0
mkdir obj
cd obj
../configure --prefix=$PREFIX --build=`../config.guess` --host=avr
make -j16
make install
cd ../../
cd gcc-10.2.0
cd obj
../configure --prefix=$PREFIX --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2 --with-newlib --disable-__cxa_atexit --disable-threads --disable-shared --disable-sjlj-exceptions --enable-libstdcxx --disable-hosted-libstdcxx --disable-bootstrap
make -j16
make install
@bstaletic
Copy link

Hey, thanks for this script! I have just one more question. Is there any special reason for --with-newlib? I haven't yet looked at gcc's ./configure --help, but I'm assuming that switch makes gcc link against newlib instead of... glibc?

@ricardocosme
Copy link
Author

Hey, thanks for this script!

It's good to know that it is useful to you.

I have just one more question. Is there any special reason for --with-newlib?

Yes, it's a workaround to not check for dlopen().

I haven't yet looked at gcc's ./configure --help, but I'm assuming that switch makes gcc link against newlib instead of... glibc?

Actually we're using avr-libc here instead of glibc or newlib.

@bstaletic
Copy link

Actually we're using avr-libc here instead of glibc or newlib.

That's exactly what confused me - "where's newlib coming from, if AVR uses avr-libc?"

I do have a mostly working avr-gcc toolchain, but I'm missing the C++ standard library, so will try recompiling with this script's instructions.

@ricardocosme
Copy link
Author

That's exactly what confused me - "where's newlib coming from, if AVR uses avr-libc?"

Yes, I know, it's confusing. It's something far from ideal.

I do have a mostly working avr-gcc toolchain, but I'm missing the C++ standard library, so will try recompiling with this script's instructions.

Right. Here, I use the version of avr-gcc with libstdc++ using freestanding as my main toolchain and the avr-gcc without libstdc++ only to test the support that my libraries offer when the programmer doesn't have libstdc++.

@SpyrosMourelatos
Copy link

SpyrosMourelatos commented Sep 6, 2021

Just two hints for people that in general compile gcc for the first time (like me).
You should define a $PREFIX that you have write access on for the installations to work like:

PREFIX=$HOME/local/avr
export PREFIX
PATH=$PATH:$PREFIX/bin

And you should install on your shared libs GMP,MPFR and MPC , this can be easily done after line 24(so in gcc's folder) by running the
script

./contrib/download_prerequisites

@SpyrosMourelatos
Copy link

SpyrosMourelatos commented Sep 9, 2021

Also a question @ricarocosme ,what if we want all the headers of the stl like variant and such , would it work to just remove some of your -disable flags?

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