Post

Set the default gcc version on a Raspberry Pi

My first experience with my Raspberry Pi was to compile some stuff. I needed an older gcc version than was pre-installed on wheezy. Installation wasn’t the problem, the problem was to use the right gcc version. After searching the web I found a helper script created by Jeff Carr-3.

Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

usage() {
        echo
        echo Sets the default version of gcc, g++, etc
        echo Usage:
        echo
        echo "    gcc-set-default-version <VERSION>"
        echo
        exit
}

cd /usr/bin

if [ -z $1 ] ; then
        usage;
fi

set_default() {
        if [ -e "$1-$2" ] ; then
                echo $1-$2 is now the default
                ln -sf $1-$2 $1
        else
                echo $1-$2 is not installed
        fi
}

for i in gcc cpp g++ gcov gccbug ; do
        set_default $i $1
done

Usage

1
sudo sh gcc-set-default-version 4.7
This post is licensed under CC BY 4.0 by the author.