joyrider3774
Posts: 35
Joined: Sun Mar 13, 2016 12:21 pm

is it possible to compile a newer gcc/ g++ on the pi itselve

Wed Mar 16, 2016 1:30 pm

Hi,

I'm wondering about speed diffrences between compiler versions when building applications with the same flags just diffrent compiler version and what kind of improvements there might be either negative or positive.

While i managed to build a cross compiler on a virtual machine on my pcc and could build a simple hello world application that would run on the pi afterwards. i did not manage to get more complex projects builded.

This evening i might start with trying to crosscompile a simple benchmark program though and if i succeed start by comparing that to the the current compiler version being used on the pi it selve.

Anyway since i'm not that good at cross compiling things but generaly do manage to build projects on the target system itselve i'm wondering if it's possible to compile a new gcc / g++ version from source on the pi itselve that can be used to compile on the pi then.

I do not know if anyone has done this before because it would probablly take a long long time to get it compiled but leaving the build time out of the question, is this at all possible and would this pose problems with the current stock compiler installed on pi (4.9.2 i think it is)

User avatar
RaTTuS
Posts: 10539
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: is it possible to compile a newer gcc/ g++ on the pi its

Wed Mar 16, 2016 1:43 pm

get the source for the compiler
./configure
make -j4
possibly - read the readme that comes with the source
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

jahboater
Posts: 5216
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: is it possible to compile a newer gcc/ g++ on the pi its

Wed Mar 16, 2016 5:22 pm

Try this. Takes 5 hours on a Pi3 (less if you have a heatsink).
The ./configure line will need changing for a different Pi (change the v8 to v7) and if you want to install it in a different place.
You can download it directly from the gcc website.
gcc 5.3 is the latest version.

Code: Select all

wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-5.3.0/gcc-5.3.0.tar.bz2
tar xvf gcc-5.3.0.tar.bz2
cd gcc-5.3.0
contrib/download_prerequisites
mkdir obj
cd obj

../configure -v --enable-languages=c,c++ \
  --prefix=/home/pi/gcc-5.3 --with-arch=armv8-a \
  --with-fpu=neon-vfpv4 --with-float=hard --build=arm-linux-gnueabihf \
  --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf

sudo dd if=/dev/zero of=/swapfile1GB bs=1M count=1024
sudo mkswap /swapfile1GB
sudo swapon /swapfile1GB

make -j5
sudo make install
"We are in the beginning of a mass extinction, and all you can talk
about is money and fairy tales of eternal economic growth."
- Greta Thunberg

User avatar
RaTTuS
Posts: 10539
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: is it possible to compile a newer gcc/ g++ on the pi its

Wed Mar 16, 2016 5:23 pm

if you have more than one Pi3 then distcc will also help
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: is it possible to compile a newer gcc/ g++ on the pi its

Wed Mar 16, 2016 5:58 pm

RaTTuS wrote:if you have more than one Pi3 then distcc will also help
Of course if he's hacking it, that might matter but if he's just building it for use, one time and let the thing run overnight should do it.
jahboater wrote: sudo mkswap /swapfile1GB
sudo swapon /swapfile1GB

make -j5
-j5 is what I've seen others claim is best supposedly because you want one more than the number of cores.

But does this really get into the swap file? Just on the link? Because that could be a limiting factor, and hopefully the person doing this doesn't have a dodgy sdcard.

jahboater
Posts: 5216
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: is it possible to compile a newer gcc/ g++ on the pi its

Wed Mar 16, 2016 6:20 pm

stderr wrote:-j5 is what I've seen others claim is best supposedly because you want one more than the number of cores.

But does this really get into the swap file? Just on the link? Because that could be a limiting factor, and hopefully the person doing this doesn't have a dodgy sdcard.
You always want at least four runnable processes, so if some are held up by I/O then others can use a CPU. Ncpus + 1 gave good results for me on a Pi. You could try 6 or 7. It probably depends on the speed of the disk. On my Intel box with 16GB of memory I do the entire build on a ram disk and then any -j greater than 4 has no benefit because its never waiting for I/O.

It does swap quite heavily at one point only, for a few minutes near the start of the build, with -j1 (and probably 2) you don't need the swapfile, but the build takes ages.
"We are in the beginning of a mass extinction, and all you can talk
about is money and fairy tales of eternal economic growth."
- Greta Thunberg

lilunxm12
Posts: 7
Joined: Fri Mar 04, 2016 6:19 am

Re: is it possible to compile a newer gcc/ g++ on the pi its

Sat Apr 23, 2016 12:12 pm

jahboater wrote:Try this. Takes 5 hours on a Pi3 (less if you have a heatsink).
The ./configure line will need changing for a different Pi (change the v8 to v7) and if you want to install it in a different place.
You can download it directly from the gcc website.
gcc 5.3 is the latest version.

Code: Select all

wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-5.3.0/gcc-5.3.0.tar.bz2
tar xvf gcc-5.3.0.tar.bz2
cd gcc-5.3.0
contrib/download_prerequisites
mkdir obj
cd obj

../configure -v --enable-languages=c,c++ \
  --prefix=/home/pi/gcc-5.3 --with-arch=armv8-a \
  --with-fpu=neon-vfpv4 --with-float=hard --build=arm-linux-gnueabihf \
  --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf

sudo dd if=/dev/zero of=/swapfile1GB bs=1M count=1024
sudo mkswap /swapfile1GB
sudo swapon /swapfile1GB

make -j5
sudo make install
shouldn't we use --with-fpu=crypto-neon-fp-armv8 for pi3?

jahboater
Posts: 5216
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: is it possible to compile a newer gcc/ g++ on the pi its

Sat Apr 23, 2016 6:19 pm

lilunxm12 wrote:shouldn't we use --with-fpu=crypto-neon-fp-armv8 for pi3?
Yes. But its just a default.
"We are in the beginning of a mass extinction, and all you can talk
about is money and fairy tales of eternal economic growth."
- Greta Thunberg

lilunxm12
Posts: 7
Joined: Fri Mar 04, 2016 6:19 am

Re: is it possible to compile a newer gcc/ g++ on the pi its

Sat Apr 23, 2016 7:20 pm

jahboater wrote:
lilunxm12 wrote:shouldn't we use --with-fpu=crypto-neon-fp-armv8 for pi3?
Yes. But its just a default.
thx. just want to make sure as there's no document confirms a53 should use --with-fpu=crypto-neon-fp-armv8 and. I compiled 2 nbench for test and apparently --with-fpu=neon-vfpv4 seems to yield higher score.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: is it possible to compile a newer gcc/ g++ on the pi its

Sat Apr 23, 2016 8:39 pm

Not sure how many of you are familiar with Julia (special purpose REPL | compiler) which combines clang, LLVM, Fortran, and some other stuff for working with arrays (matrices); hasn't caught on BIG yet, but they're on their way...

... anyways, takes all day to compile it from sources. On a really fast machine it takes several hours; and you kinda need to baby-sit it...

I put it in the background and nice it... I don't try to disttrib it either... just let it run (keep doing my other work) check on it from time to time...

Compiling Julia reminds of the days when we were trying to compile the Linux kernel on a 486 machine running 300 Mhz... :?
marcus
:ugeek:

jahboater
Posts: 5216
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: is it possible to compile a newer gcc/ g++ on the pi its

Sat Apr 23, 2016 10:57 pm

thx. just want to make sure as there's no document confirms a53 should use --with-fpu=crypto-neon-fp-armv8 and. I compiled 2 nbench for test and apparently --with-fpu=neon-vfpv4 seems to yield higher score.
I cant explain the higher score. but I found that -mfpu=neon-fp-armv8 gave a better fit to the available ARM v8 NEON instructions - a few math functions reduce to single neon instructions which are new to v8 neon.

For example fmax() becomes the new neon "vmaxnm" instruction with -mfpu=neon-fp-armv8, whereas with -mfpu=neon-vfpv4 gcc emitted code to do it by hand:

Code: Select all

    vcmpe.f64   d8, d9 
    vmrs        APSR_nzcv, FPSCR
    vmovhi.f64  d8, d9 
"We are in the beginning of a mass extinction, and all you can talk
about is money and fairy tales of eternal economic growth."
- Greta Thunberg

Return to “C/C++”