读好书,交益友
分类: C/C++
2012-10-11 20:13:12
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
解压缩gmp5.05
cd gmp-5.0.5/
mkdir build && cd build
../configure --prefix=/usr/gcc_4_7 –build=x86_64-linux-gnu
make
make install
安装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
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
安装成功
新建文件
#include
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吧