How to change the default GCC compiler in Ubuntu?

后端 未结 8 1393
孤街浪徒
孤街浪徒 2020-11-28 17:44

I have installed gcc-3.3/g++-3.3 on ubuntu 11.04 which already has gcc/g++-4.4. So in my system both gcc-3.3 and 4.4 are available. I am able to call both compilers as I wan

相关标签:
8条回答
  • 2020-11-28 18:40

    I used just the lines below and it worked. I just wanted to compile VirtualBox and VMWare WorkStation using kernel 4.8.10 on Ubuntu 14.04. Initially, most things were not working for example graphics and networking. I was lucky that VMWare workstation requested for gcc 6.2.0. I couldn't start my Genymotion Android emulators because virtualbox was down. Will post results later if necessary.

    VER=4.6 ; PRIO=60
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
    VER=6 ; PRIO=50
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
    VER=4.8 ; PRIO=40
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
    
    0 讨论(0)
  • 2020-11-28 18:48

    In case you want a quicker (but still very clean) way of achieving it for a personal purpose (for instance if you want to build a specific project having some strong requirements concerning the version of the compiler), just follow the following steps:

    • type echo $PATH and look for a personal directory having a very high priority (in my case, I have ~/.local/bin);
    • add the symbolic links in this directory:

    For instance:

    ln -s /usr/bin/gcc-WHATEVER ~/.local/bin/gcc
    ln -s /usr/bin/g++-WHATEVER ~/.local/bin/g++
    

    Of course, this will work for a single user (it isn't a system wide solution), but on the other hand I don't like to change too many things in my installation.

    0 讨论(0)
提交回复
热议问题