knute
Posts: 804
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas

gcc 10+?

Thu Dec 10, 2020 3:52 am

A while back there was a thread with a script for downloading and compiling gcc 10 (I think it was 10 anyway). I can't seem to find it again. I have need for gcc 10. Anybody remember who posted the script or what the title was?

User avatar
jahboater
Posts: 8126
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: gcc 10+?

Thu Dec 10, 2020 4:31 am

Here it is:

Code: Select all

#!/bin/bash

# REMEMBER TO UNCOMMENT THE CONFIGURE LINE FOR YOUR TARGET PLATFORM.
# ... and comment out the default of course.

#
#  This is the new GCC version to install.
#
VERSION=10.2.0

#
#  These are the languages the new compiler should support.
#
LANG=c,c++,fortran

#
#  For any computer with less than 2GB of memory.
#
#if [ -f /etc/dphys-swapfile ]; then
#  sudo sed -i 's/^CONF_SWAPSIZE=[0-9]*$/CONF_SWAPSIZE=1024/' /etc/dphys-swapfile
#  sudo /etc/init.d/dphys-swapfile restart
#fi

if [ -d gcc-$VERSION ]; then
  cd gcc-$VERSION
  rm -rf obj
else
  echo "Download source tree ..."
  wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-$VERSION/gcc-$VERSION.tar.xz
  echo "Uncompress source tree ..."
  tar xf gcc-$VERSION.tar.xz
  rm -f gcc-$VERSION.tar.xz
  cd gcc-$VERSION
  contrib/download_prerequisites
fi
mkdir -p obj
cd obj

#
#  Now run the ./configure which must be checked/edited beforehand.
#  Uncomment the sections below depending on your platform.  You may build
#  on a Pi3 for a target Pi Zero by uncommenting the Pi Zero section.
#  To alter the target directory set --prefix=<dir>
#  For a very quick build try: --disable-bootstrap
#

# x86_64
#../configure --disable-multilib --enable-languages=$LANG

# AArch64 Pi4 running Raspberry Pi OS 64-bit
../configure --enable-languages=$LANG --with-cpu=cortex-a72

# Pi Zero
#../configure --enable-languages=$LANG --with-cpu=arm1176jzf-s \
#  --with-fpu=vfp --with-float=hard --build=arm-linux-gnueabihf \
#  --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf

# Pi3+, Pi3, Pi4 in 32-bit mode
#../configure --enable-languages=$LANG --with-cpu=cortex-a53 \
#  --with-fpu=neon-fp-armv8 --with-float=hard --build=arm-linux-gnueabihf \
#  --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf

# Old Pi2
#../configure --enable-languages=$LANG --with-cpu=cortex-a7 \
#  --with-fpu=neon-vfpv4 --with-float=hard --build=arm-linux-gnueabihf \
#  --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf

#
#  Now build GCC which will take a long time.  This could range from
#  3.5 hours on a 4GB Pi4 up to about 50 hours on a Pi Zero.  It can be
#  left to complete overnight (or over the weekend for a Pi Zero :-)
#  The most likely causes of failure are lack of disk space, lack of
#  swap space or memory, or the wrong configure section uncommented.
#  The new compiler is placed in /usr/local/bin, the existing compiler remains
#  in /usr/bin and may be used by giving its version gcc-6 (say).
#
if make -j `nproc`
then
  echo
  read -p "Do you wish to install the new GCC (y/n)? " yn
  case $yn in
   [Yy]* ) sudo make install ;;
     * ) exit ;;
  esac
fi
Last edited by jahboater on Fri Dec 11, 2020 2:10 am, edited 1 time in total.

knute
Posts: 804
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas

Re: gcc 10+?

Thu Dec 10, 2020 4:11 pm

Thanks for that!

One other question. Is there any advantage of recompiling 10 with 10?

User avatar
jahboater
Posts: 8126
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: gcc 10+?

Thu Dec 10, 2020 4:32 pm

knute wrote:
Thu Dec 10, 2020 4:11 pm
Is there any advantage of recompiling 10 with 10?
That's what happens anyway as the final part of the normal build (one of the reasons it takes so long).

knute
Posts: 804
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas

Re: gcc 10+?

Fri Dec 11, 2020 12:24 am

jahboater wrote:
Thu Dec 10, 2020 4:32 pm
knute wrote:
Thu Dec 10, 2020 4:11 pm
Is there any advantage of recompiling 10 with 10?
That's what happens anyway as the final part of the normal build (one of the reasons it takes so long).
Thanks.

One more question, I've compiled it but how do I install it somewhere?

User avatar
jahboater
Posts: 8126
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: gcc 10+?

Fri Dec 11, 2020 2:09 am

In the same directory that you typed "make", type:

sudo make install

then, type "gcc -v" to confirm the version of the new compiler.

knute
Posts: 804
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas

Re: gcc 10+?

Fri Dec 11, 2020 3:35 am

You flipped the script on me :-). I ran the original script from ~/bin. It created a directory gcc-10.2.0. There was no Makefile in ~/bin so I went to ~/bin/gcc-10.2.0/obj and entered sudo make install. I think it is working like it is supposed to. It needed a restart of the terminal.

Thanks again.

graham.reeds
Posts: 14
Joined: Tue Mar 31, 2020 1:35 pm

Re: gcc 10+?

Mon Mar 29, 2021 10:03 am

This (as does the previous thread) fails for me. I have the latest RaspiOS with arm_64bit enabled. Does that matters?

fruitoftheloom
Posts: 27225
Joined: Tue Mar 25, 2014 12:40 pm

Re: gcc 10+?

Mon Mar 29, 2021 10:16 am

graham.reeds wrote:
Mon Mar 29, 2021 10:03 am
This (as does the previous thread) fails for me. I have the latest RaspiOS with arm_64bit enabled. Does that matters?

FYI arm_64bit changes the Kernel to 64bit, but Userland is still 32bit.
Take what I advise as advice not the utopian holy grail, and it is gratis !!

graham.reeds
Posts: 14
Joined: Tue Mar 31, 2020 1:35 pm

Re: gcc 10+?

Mon Mar 29, 2021 3:28 pm

Is there any way of getting a 64bit tool chain?

Heater
Posts: 19061
Joined: Tue Jul 17, 2012 3:02 pm

Re: gcc 10+?

Mon Mar 29, 2021 3:58 pm

graham.reeds wrote:
Mon Mar 29, 2021 3:28 pm
Is there any way of getting a 64bit tool chain?
I have been using 64 bit GCC and Rust by using the nspawn 64 bit container environment:

Code: Select all

pi@heater-pi:~ $ sudo apt-get install raspbian-nspawn-64
pi@heater-pi:~ $ ds64-shell 
pi@debian-buster-64:~ $ Connected to machine debian-buster-64. Press ^] three times within 1s to exit session.
pi@debian-buster-64:~ $ sudo apt-get install gcc
pi@debian-buster-64:~ $ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/8/lto-wrapper
Target: aarch64-linux-gnu
...
...
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6) 
$ gcc hello.c 
pi@debian-buster-64:~ $ file ./a.out 
./a.out: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=ecb9ffc2d6736670604025bd67d48b6e08c2a8ab, not stripped
Memory in C++ is a leaky abstraction .

User avatar
jahboater
Posts: 8126
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: gcc 10+?

Mon Mar 29, 2021 6:11 pm

graham.reeds wrote:
Mon Mar 29, 2021 3:28 pm
Is there any way of getting a 64bit tool chain?
I use the 64-bit version of Raspberry Pi OS and build GCC with this simple configure line:

Code: Select all

../configure --enable-languages=c,d,c++,fortran --with-cpu=cortex-a72
Then I get the full 64-bit tool chain and compiler for the Pi4.

Return to “C/C++”