How to use an older version of gcc in Linux

前端 未结 4 1214
太阳男子
太阳男子 2020-12-20 13:39

In Linux I am trying to compile something that uses the -fwritable-strings option. Apparently this is a gcc option that doesn\'t work in newer version of gcc. I installed gc

4条回答
  •  不思量自难忘°
    2020-12-20 14:05

    If editing the configuration/Makefile is not an option, Linux includes a utility called update-alternatives for such situations. However, it's a pain to use (links to various tutorials included below).

    This is a little simpler - here's a script (from here) to easily switch your default gcc/g++ version:

    #!/bin/bash 
    usage() {
            echo 
            echo Sets the default version of gcc, g++, etc
            echo Usage:
            echo 
            echo "    gcc-set-default-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
    

    If you 1) name this script switch-gcc, 2) put it in your path, and 3) make it executable (chmod +x switch-gcc), you can then switch compiler versions just by running

    sudo switch-gcc 3.2

    Further reading on update-alternatives:

    • https://lektiondestages.blogspot.com/2013/05/installing-and-switching-gccg-versions.html
    • https://codeyarns.com/2015/02/26/how-to-switch-gcc-version-using-update-alternatives/
    • https://askubuntu.com/questions/26498/choose-gcc-and-g-version

提交回复
热议问题