安装gcc-4.8 示例错误方法 和 正确方法 --linux下用c++ 11

来源:互联网 发布:龙虎榜数据 同花顺 编辑:程序博客网 时间:2024/06/04 18:18


国外网站比较慢,所以我会放上我下载的软件包。


这是错误做法:
1:
configure gcc,显示requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+。
2:
下载这三个文件。ftp://ftp.gnu.org/gnu/gmp 选择自己想要的版本。
其他同理。参考 http://www.multiprecision.org/mpc
     http://ftp.gnu.org/gnu/mpfr


3:
安装GMP:直接./configure,make,make check,sudo make install
4:
安装MPFR:./configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib , 
之后make顺利
make check显示有错,
问题如下:
[tversion] GMP: header 5.1.3, library 5.0.2
[tversion] MPFR tuning parameters from src/x86/core2/mparam.h
ERROR! The versions of gmp.h (5.1.3) and libgmp (5.0.2) do not match.
The possible causes are:
  * A bad configuration in your include/library search paths.
  * An inconsistency in the include/library search paths of
    your development environment; an example:
      http://gcc.gnu.org/ml/gcc-help/2010-11/msg00359.html
  * GMP has been upgraded after the first "make check".
    In such a case, try again after a "make clean".
  * A new or non-standard version naming is used in GMP.
    In this case, a patch may already be available on the
    MPFR web site.  Otherwise please report the problem.
In the first two cases, this may lead to errors, in particular with MPFR.
If some other tests fail, please solve that problem first.
FAIL: tversion
=====================
2 of 160 tests failed
(1 test was not run)
=====================




正确做法:


删除gmp,方法是进入gmp目录,sudo make uninstall.


重新做第3步:在gmp-5.1.3同级目录下建立一个临时的编译目录,这里命名为temp。然后开始配置安装选项,进入temp目录,输入以下命令进行配置:
      ../gmp-5.1.3/configure --prefix=/usr/local/gmp-5.1.3.


之前的方法在/usr/local没有单独的gmp-5.1.3这个单独文件。gmp-5.1.3的.h,gmplib,dir和.info这些文件分散在local里的include,lib,和share里。而
单独放到一个文件里在配置MPFR的时候--with-gmp=/usr/local/gmp-5.1.3而不是--with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib
可以防止出现出现The versions of gmp.h (5.1.3) and libgmp (5.0.2) do not match这样的情况出现。


之所以用temp这个临时的编译目录,而不是当前目录下configure,是因为tar.bz2是纯净的c语言源代码,在configure和make之后生成的和本机相关的二进制文件和源代码混到一起,怎么给别人用?如果安装失败的话,有时重新configure的时候,还要make distclean。


重新做第4步:./configure --with-gmp=/usr/local/gmp-5.1.3.


第5步:../mpc-1.0.1/configure --prefix=/usr/local/mpc-1.0.1 --with-gmp=/usr/local/gmp-5.1.3 --with-mpfr=/usr/local/mpfr-3.1.2


第6步:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-1.0.1/lib:/usr/local/gmp-5.1.3/lib:/usr/local/mpfr-3.1.2/lib 




第7步:再次建立一个temp(可选,我洁癖)../gcc-4.8.0/configure --prefix=/usr/local/gcc-4.8.0 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++
  --with-gmp=/usr/local/gmp-5.1.3 --with-mpfr=/usr/local/mpfr-3.1.2 --with-mpc=/usr/local/mpc-1.0.1
然后接着make,时间非常长,建议吃个饭,再散散步。
这次如果时间着急的话,可以不用make check,时间太漫长了
接着sudo make install
完成了。


不过,还不是完美。因为如果这个时候输入gcc -v 或者是 g++ -v,依旧是我原来的4.6.3.
因为文件安装在/usr/local/gcc-4.8.0里。

which g++看到在/usr/bin/gcc,所以系统原先的gcc没有被覆盖。默认的依旧是4.6.3,如果要用4.8.0还要每次改Makefile的CC =。我的办法是,把现有的/usr/bin做个备份,然后把gcc-4.8.0里的文件覆盖到里面,再g++ -v就对了。


但是,千万别着急删除备份,存一段时间,由于我用的NS-3目前尚不支持gcc-4.8.0,于是我只好再换回来,只能makefile了~

0 0
原创粉丝点击