通过切换到新编译器,将Ubuntu 12.04上的GCC 4.6.3升级到4.8.2

时间:2015-01-15 00:43:26

标签: c++ ubuntu gcc g++

我想从g ++ 4.6.3升级到4.8,然后使用新的编译器。

注意:下面的make失败了!

../.././libcc1/findcomp.cc:20:20: fatal error: config.h: No such file or directory compilation terminated.

来自this回答:

sudo apt-get install libmpfr-dev libgmp3-dev libmpc-dev flex bison

svn checkout svn://gcc.gnu.org/svn/gcc/trunk

cd trunk

./configure --prefix=/opt/gcc-4.8.2/usr/local/gcc-4.8.2 --enable-languages=c,c++

make

make install

编译器将放在/ opt /目录中,因此您必须从那里使用它。

我的问题是(如果您认为上述步骤有误,请说明一下):

  1. 现在有更简单的方法吗?
  2. 如何执行最后一步?我的意思是,我想我可以做/opt/g++-4.8或 什么,但我必须这样做,以便我的系统看到 我用g ++编译时的编译器?

  3. 相关question

1 个答案:

答案 0 :(得分:0)

我只是展示一个想法,如何通过在shell中切换来适应不同的编译器

我根据我的安装情况向您提供了解决方案,前提是您已经知道最新g++和以前版本的g++的位置。我想这样做:

#I create some color for $PS1 use
black="\[\033[1;30m\]"
red="\[\033[1;31m\]"
green="\[\033[1;32m\]"
yellow="\[\033[1;33m\]"
blue="\[\033[1;34m\]"
purple="\[\033[1;35m\]"
cyan="\[\033[1;36m\]"
white="\[\033[1;37m\]"
coloroff="\[\033[0m\]"
highlight="\[\033[1m\]"
underline="\[\033[4m\]"
twinkle="\[\033[5m\]"
reverse="\[\033[7m\]"
unvisible="\[\033[8m\]"

#you can add some default path, I just list my daily use path for you, you need modify them
DEFAULT_PATH="/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$HOME/bin"

#default setting, I usually use gcc, so you need modify to g++
function default(){
export PATH="$DEFAULT_PATH"
PS1="\[\033]2;\u@\h:\w\a\]$red[GNU-GCC]$blue\u@\h:$coloroff\w\n-> "
gcc_ver=`gcc --version | head -n 1`
}

#you can add more compiler, even some dedicate old version of g++, just copy my function and modify the bin path

#arm-linux-gcc setting, I also use cross compiler
function armlinuxgcc(){
export PATH="$DEFAULT_PATH"
PS1="\[\033]2;\u@\h:\w\a\]$red[ARM-Linux-GCC]$blue\u@\h:$coloroff\w\n-> "
arm_linux_gcc_ver=`arm-linux-gnueabi-gcc-4.7 --version | head -n 1`
}

#I also use dedicate compiler provide by arm
function RVCT22B616(){
#for RVCT2.2
export PATH="$DEFAULT_PATH:$HOME/Software/RVS22-BN-00000-r2p2-01rel0/rvds_2_2_1_dist241_linux/RVCT/Programs/2.2/503/linux-pentium"
export RVCT22INC="$HOME/Software/RVS22-BN-00000-r2p2-01rel0/rvds_2_2_1_dist241_linux/RVCT/Data/2.2/503/include/unix"
export RVCT22LIB="$HOME/Software/RVS22-BN-00000-r2p2-01rel0/rvds_2_2_1_dist241_linux/RVCT/Data/2.2/503/lib"
PS1="\[\033]2;\u@\h:\w\a\]$red[ARM2.2B616]$blue\u@\h:$coloroff\w\n-> "
armcc_ver=`armcc --vsn | head -n 1`
#end of RVCT2.2
}

function RVCT31B1055(){         
#for RVCT3.1
export PATH="$DEFAULT_PATH:$HOME/Software/RVP31-PA-00001-r3p1-09rel0/linux-pentium"
export RVCT31INC="$HOME/Software/RVP31-PA-00001-r3p1-09rel0/include/unix"
export RVCT31LIB="$HOME/Software/RVP31-PA-00001-r3p1-09rel0/lib"
PS1="\[\033]2;\u@\h:\w\a\]$red[ARM3.1B1055]$blue\u@\h:$coloroff\w\n-> "
armcc_ver=`armcc --vsn | head -n 1`
#end of RVCT3.1
}

function RVCT41B894(){
#for RVCT4.1
export PATH="$DEFAULT_PATH:$HOME/Software/RVP41-PA-00001-r4p1-05rel0/standard-linux-pentium-rel/linux-pentium"
export ARMCC41INC="$HOME/Software/RVP41-PA-00001-r4p1-05rel0/standard-linux-pentium-rel/include/unix"
export ARMCC41LIB="$HOME/Software/RVP41-PA-00001-r4p1-05rel0/standard-linux-pentium-rel/lib"
PS1="\[\033]2;\u@\h:\w\a\]$red[ARM4.1B894]$blue\u@\h:$coloroff\w\n-> "
armcc_ver=`armcc --vsn | head -n 1`
#end of RVCT4.1
}

function DS5B94(){
#for DS-5
export PATH="$DEFAULT_PATH:/usr/local/DS-5/bin/"
export ARMCC5INC="/usr/local/DS-5/include/"
PS1="\[\033]2;\u@\h:\w\a\]$red[ARM5.0B94]$blue\u@\h:$coloroff\w\n-> "
armcc_ver=`armcc --vsn | head -n 1`
#end of DS-5
}

然后,让用户可以选择这些编译器:

default
function sel_env(){
echo "**************************"
echo "* Switch Compile env:"
echo "* 1. ARMCC 2.2 Build[616]"
echo "* 2. ARMCC 3.1 Build[1055]"
echo "* 3. ARMCC 4.1 Build[894]"
echo "* 4. ARMCC 5.0 Build[94]"
echo "* 5. ARM-Linux-GUNEABI-GCC"
echo "* 6. GCC"
echo "**************************"
read choose;
#select choose in "1" "2" "3"; do
    case $choose in
        1) RVCT22B616
            echo "CC -> $armcc_ver"
            echo "Compile Firmware and Boot Core";;
        2) RVCT31B1055
            echo "CC -> $armcc_ver"
            echo "Compile Boot Core";;
        3) RVCT41B894
            echo "CC -> $armcc_ver"
            echo "Compile Firmware";;
        4) DS5B94
            echo "CC -> $armcc_ver"
            echo "Compile Firmware";;
        5) armlinuxgcc 
            echo "CC -> $arm_linux_gcc_ver"
            echo "Corss compile";;
        *) default
            echo "CC -> $gcc_ver";;
    esac
#done
}

现在,在您打开终端后,首先source此env文件,或在.bashrc的{​​{1}}文件中添加此操作,然后输入$HOME。如果你只是sel_env这个文件,我会告诉你结果:

source

然后如果我选择how@ubuntu-sw:~/Work/.env$ ls work.env how@ubuntu-sw:~/Work/.env$ source work.env [GNU-GCC]how@ubuntu-sw:~/Work/.env -> ls work.env [GNU-GCC]how@ubuntu-sw:~/Work/.env -> sel_env ************************** * Switch Compile env: * 1. ARMCC 2.2 Build[616] * 2. ARMCC 3.1 Build[1055] * 3. ARMCC 4.1 Build[894] * 4. ARMCC 5.0 Build[94] * 5. ARM-Linux-GUNEABI-GCC * 6. GCC ************************** 例如:

1

希望此选项可以在您处理多个编译器时提供帮助。如果您认为这种方式过于过度,我建议您也可以使用符号链接,并且因为您将编译器安装到[GNU-GCC]how@ubuntu-sw:~/Work/.env -> sel_env ************************** * Switch Compile env: * 1. ARMCC 2.2 Build[616] * 2. ARMCC 3.1 Build[1055] * 3. ARMCC 4.1 Build[894] * 4. ARMCC 5.0 Build[94] * 5. ARM-Linux-GUNEABI-GCC * 6. GCC ************************** 1 ARM/Thumb C/C++ Compiler, RVCT2.2 [Build 616] CC -> Compile Firmware and Boot Core [ARM2.2B616]how@ubuntu-sw:~/Work/.env -> ,通常这个/opt文件夹应该在您的系统定义路径中。但是你需要以某种方式运行/opt,然后你可以创建一个符号链接g++_withyour_version,然后,你只能为版本4.8.2键入ln -s /opt/gcc-4.8.2 /opt/gcc