ubuntu中安装gcc 4.7,比centos要复杂些。
如果出现如下的提示:
configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
必须要安装mpc, mpfr and gmp,下面分步骤进行。
编译gmp5.05
安装MPFR
cd mpfr-3.1.1/
mkdir build && cd build
../configure --build=x86_64-linux-gnu --prefix=/usr/gcc_4_7 --with-gmp=/usr/gcc_4_7 –with-mpfr=/usr/gcc_4_7
make
sudo make install
安装mpc 0.8.2
cd mpc-0.8.2/
mkdir build && cd build
../configure --build=x86_64-linux-gnu --prefix=/usr/gcc_4_7 --with-gmp=/usr/gcc_4_7 –with-mpfr=/usr/gcc_4_7
make
sudo make install
编译gcc
#下载gcc 4.7.1 :
wget http://gcc-uk.internet.bs/releases/gcc-4.7.1/gcc-4.7.1.tar.bz2
cd gcc-4.7.1/
mkdir build && cd build
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/
export C_include_PATH=/usr/include/x86_64-linux-gnu
export CPLUS_INCLUDE_PATH=/usr/include/x86_64-linux-gnu
../configure --build=x86_64-linux-gnu --prefix=/usr/gcc_4_7 --with-gmp=/usr/gcc_4_7 --with-mpfr=/usr/gcc_4_7 --with-mpc=/usr/gcc_4_7 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib –program-suffix=-4.7
make
sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64
sudo make install
加入.bashrc
cd ~
gedit .bashrc
添加
export PATH=/usr/gcc_4_7/bin:$PATH
export C_INCLUDE_PATH=/usr/include/x86_64-linux-gnu:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH
export OBJC_INCLUDE_PATH=$C_INCLUDE_PATH
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH
运行
. .bashrc
运行
g++-4.7 –version
显示
g++-4.7 (GCC) 4.7.1
则表示成功安装。
新建文件,测试下gcc。
#include <iostream>
using namespace std;
int main() {
cout << [](int m, int n) { return m + n;} (2,4) << endl;
return 0;
}
编译
g++ -std=c++11 main.cpp
经过一阵子的折腾,发现codeblocks和monodevelop 真难用,还是使用eclipse吧。