# GCC Compiler Versions

**URL:** <https://forums.suse.com/t/gcc-compiler-versions/30063>\
**Category:** SLES for Raspberry Pi\
**Created:** [July 19, 2017, 7:37am UTC](https://forums.suse.com/t/gcc-compiler-versions/30063 "2017-07-19T07:37:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![digbyt](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@digbyt](https://forums.suse.com/u/digbyt)\
**Post date:** [July 19, 2017, 7:37am UTC](https://forums.suse.com/t/gcc-compiler-versions/30063/1 "2017-07-19T07:37:06Z")

</div>

Section 4.2 of the installation instructions (Introduction to SUSE Linux Enterprise Server for the Raspberry Pi) strongly recommends the use of ‘gcc-6’, which is GCC V6.2.1, rather than the default gcc/cc which is V4.8.5.

I assume that this cannot be done for everything - otherwise the old compiler would have just been replaced. Can anyone tell me what requires the older 4.8.5 compiler such that it has to be made the default?

Which compiler was used to build the kernel (assuming kernel modules need to be built with the same one)?

Thanks,  
DigbyT

---

<div class="post-metadata">

**Author:** ![malcolmlewis](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/malcolmlewis/32/11375_2.png) [@malcolmlewis](https://forums.suse.com/u/malcolmlewis)\
**Post date:** [July 19, 2017, 3:13pm UTC](https://forums.suse.com/t/gcc-compiler-versions/30063/2 "2017-07-19T15:13:47Z")

</div>

Hi  
To see the gcc version used to compile the kernel is…

```auto
cat /proc/version
Linux version 4.4.74-92.29-default (geeko@buildhost) (gcc version 4.8.5 (SUSE Linux) ) #1 SMP Thu Jun 29 13:06:32 UTC 2017 (561ddb1)
```

As for the rest, I would assume it’s the default gcc (4.8.5) but would use gcc6 for my own code…

---

<div class="post-metadata">

**Author:** ![digbyt](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@digbyt](https://forums.suse.com/u/digbyt)\
**Post date:** [July 20, 2017, 4:11am UTC](https://forums.suse.com/t/gcc-compiler-versions/30063/3 "2017-07-20T04:11:52Z")

</div>

Ah yes, thanks. I forgot that the kernel version string includes the compiler used. I suppose the compiler used to build the kernel explains why the two compilers are supplied - although not why the old one is the default. It also makes me wonder what it is about the newer gcc which prevents it being used for kernel build…

It sounds easy to say ‘use gcc6 for my own code’, but in practice it is a bit tedious to have a special case on SUSE if you are trying to maintain a lot of software on a lot of different platforms. If I rsync my source tree to do a test build on SUSE, there would be a lot of makefiles to customize.

As a work around, I created the following script to switch the default between the two compilers:

[INDENT]  
#!/bin/sh

# Switch default compiler between 4.8 and 6

# 

if [“$#” != “1”] ;then  
[INDENT]arg=help[/INDENT]  
else  
[INDENT]arg=$1[/INDENT]  
fi

case “$arg” in  
[INDENT] orig) VER=4.8 ;;  
new) VER=6 ;;  
\*)

```
            echo "Usage: $0 {orig|new}"
            exit 1 ;;[/INDENT]

```

esac

echo “Switching to compiler version $VER”  
cd /usr/bin  
for LINK in gcov g++ gcc gcc-ar gcc-nm gcc-ranlib cpp c++ cc  
do  
[INDENT] TGT=$LINK  
[“$TGT” = “c++”] && TGT=g++  
[“$TGT” = “cc”] && TGT=gcc  
echo SETTING UP $LINK to $TGT-$VER  
rm -f $LINK  
ln -s $TGT-$VER $LINK[/INDENT]  
done[/INDENT]

Now I just need to remember to switch defaults back to the old compiler when I do kernel builds…

---

<div class="post-metadata">

**Author:** ![malcolmlewis](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/malcolmlewis/32/11375_2.png) [@malcolmlewis](https://forums.suse.com/u/malcolmlewis)\
**Post date:** [July 20, 2017, 4:27am UTC](https://forums.suse.com/t/gcc-compiler-versions/30063/4 "2017-07-20T04:27:25Z")

</div>

> [@](#):
>
> On Thu 20 Jul 2017 01:14:02 AM CDT, digbyt wrote:
> 
> Ah yes, thanks. I forgot that the kernel version string includes the  
> compiler used. I suppose the compiler used to build the kernel explains  
> why the two compilers are supplied - although not why the old one is the  
> default. It also makes me wonder what it is about the newer gcc which  
> prevents it being used for kernel build…
> 
> It sounds easy to say ‘use gcc6 for my own code’, but in practice it is  
> a bit tedious to have a special case on SUSE if you are trying to  
> maintain a lot of software on a lot of different platforms. If I rsync  
> my source tree to do a test build on SUSE, there would be a lot of  
> makefiles to customize.
> 
> As a work around, I created the following script to switch the default  
> between the two compilers:
> 
> #!/bin/sh
> 
> # Switch default compiler between 4.8 and 6
> 
> # 
> 
> if [“$#” != “1”] ;then
> 
> arg=help  
> else
> 
> arg=$1  
> fi
> 
> case “$arg” in
> 
> orig) VER=4.8 ;;  
> new) VER=6 ;;  
> \*)
> 
> echo “Usage: $0 {orig|new}”  
> exit 1 ;;  
> esac
> 
> echo “Switching to compiler version $VER”  
> cd /usr/bin  
> for LINK in gcov g++ gcc gcc-ar gcc-nm gcc-ranlib cpp c++ cc  
> do
> 
> TGT=$LINK  
> [“$TGT” = “c++”] && TGT=g++  
> [“$TGT” = “cc”] && TGT=gcc  
> echo SETTING UP $LINK to $TGT-$VER  
> rm -f $LINK  
> ln -s $TGT-$VER $LINK  
> done
> 
> Now I just need to remember to switch defaults back to the old compiler  
> when I do kernel builds…

Hi  
Look at using update-alternatives, have a look at this howto;  
[https://en.opensuse.org/User:Tsu2/gcc\_update-alternatives](https://en.opensuse.org/User:Tsu2/gcc_update-alternatives)

Just export your CC or CXX to point at relevant versions…?

–  
Cheers Malcolm Â°Â¿Â° SUSE Knowledge Partner (Linux Counter #276890)  
openSUSE Leap 42.2|GNOME 3.20.2|4.4.74-18.20-default  
If you find this post helpful and are logged into the web interface,  
please show your appreciation and click on the star below… Thanks!

---

<div class="post-metadata">

**Author:** ![digbyt](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@digbyt](https://forums.suse.com/u/digbyt)\
**Post date:** [July 20, 2017, 8:56am UTC](https://forums.suse.com/t/gcc-compiler-versions/30063/5 "2017-07-20T08:56:47Z")

</div>

Hi,

Thanks - that does look like a better way of doing what I have done. Of course both solutions still seem a little clumsy because they have to be done on a system wide basis using administrator privilege.

Makes me wonder if it wouldn’t perhaps be better to implement such alternatives in a more flexible way, that is better suited to a multi-user system. for example, having /usr/bin/gccx.y directories, with compiler components having their standard names in each. The symlinks would then be, for example, gcc-ar → gcc4.8/gcc-ar etc.

The advantage would be that any user could locally force one or other option by putting /usr/bin/gccx.y in their path before /usr/bin.

Regards,  
DigbyT
