0

I want to upgrade from g++ 4.6.3 to 4.8 and then use the new compiler.

CAUTION: The make below failed!

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

From this answer:

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

The compiler will be placed in the /opt/ directory, so you have to use it from there.

My questions are (if you think that the above steps are wrong, please state it):

  1. Is there an easier way now to do this?
  2. How to execute the final step? I mean, I guess I could do /opt/g++-4.8 or something, but what I have to do so that my system sees that compiler when I compile with g++?

Relevant question.

Community
  • 1
  • 1
gsamaras
  • 71,951
  • 46
  • 188
  • 305
  • 1
    how about add a symbol link or write a script to adapt different compiler? I use both these two ways in my daily life – How Chen Jan 15 '15 at 02:40
  • How can I do that? Can you please show me @HowChen, with an answer maybe? currently I am in the `make` process, so I can't test it right away. – gsamaras Jan 15 '15 at 02:41
  • do you mean you need only run `g++` and it will use your latest `g++` compiler? or you need a simple way to install new `g++`? – How Chen Jan 15 '15 at 02:43
  • What I want is to use the new compiler installed and not the old one @HowChen. – gsamaras Jan 15 '15 at 02:43
  • I update my answer for both two ways – How Chen Jan 15 '15 at 03:09

1 Answers1

0

I just show an idea, how to adapt different compiler by switch them in shell

I provide you my solution base on my installation, the precondition is you already know where is your latest g++ and previous version of g++s. I would like do in this way:

#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
}

Then, let user can choose these compiler:

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
}

now, after you open your terminal, first source this env file, or add this operation in .bashrc file in your $HOME, and just type sel_env. I show you the result if you just source this file:

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
**************************

then if I choose 1 for example:

[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
->

hope this option can help you when you work on multiple compiler. If your think this way is too over-killed, I suggest you can also use symbol link, and because your install your compiler to /opt, normally this /opt folder should in your system defined path. but you need run like g++_withyour_version somehow, then you can create a symbol link, ln -s /opt/gcc-4.8.2 /opt/gcc, then, you can only type gcc for version 4.8.2

How Chen
  • 1,340
  • 2
  • 17
  • 37
  • wow, so much work? Damn! I will test tomorrow probably, since the whole process takes too long (installing). I don't want to choose compiler, I want the new one only. – gsamaras Jan 15 '15 at 03:01
  • or normally, you can use symbol like, because your install your compiler to `/opt`, normally this `/opt` folder should in your system defined path. but you need run like `g++_withyour_version` somehow, then you can create a symbol link, `ln -s /opt/gcc-4.8.2 /opt/gcc`, then, you can only type `gcc` for version 4.8.2 – How Chen Jan 15 '15 at 03:05
  • This is not a relevant answer. It shows how to switch between compilers already installed and in the path. OP wants a compiler not available for his version of the OS, and the question does nothing to help. – Dirk Eddelbuettel Jan 15 '15 at 05:16