安装gcc 4.8.2 for cxx 11

来源:互联网 发布:unity3d模型文件格式 编辑:程序博客网 时间:2024/05/16 06:02

1  ftp://gd.tuwien.ac.at/gnu/gcc/releases/gcc-4.8.2/ 下载解压,configure报错, 报错:

configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.Try the --with-gmp, --with-mpfr and/or --with-mpc options to specifytheir locations. 

2 下载/安装三个库; 或者查看 ./contrib/download_prerequisites.sh

tar -xvf gmp-5.0.5.tar.bz2

cd gmp-5.0.5

./configure && make && make check && make install;    头文件在/usr/local/inclue/下, 库在/usr/local/lib/下


wget http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.bz2

tar xvf mpfr-3.1.2.tar.bz2

cd mpfr-3.1.2

./configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib  && make && make install


tar xvf mpc-1.0.tar.gz

cd mpc-1.0

./configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/loca/lib --with-mpfr-include=/usr/local/include --with-mpfr-lib=/usr/local/lib

make && make install


/sbin/ldconfig


3 安装gcc   https://gcc.gnu.org/install/

./configure --prefix=/usr/local/gcc-4.8.2 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local

make;报错

centos 5.4cc1plus: error: unrecognized command line option "-Wno-overlength-strings"g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)man g++没发现有这个选项。 g++版本低肿么办? 好像是4.3加入的这个选项。 得先升到4.3,再升到4.8 ?. 直接去掉这个选项试试(安装成功、程序运行也没多大问题。该选项是和超长字符串有关509)。centos 6.4  64位g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4) 没这问题

configure: error: cannot compute suffix of object files: cannot compile。将依赖库路径加到搜索路径下, /sbin/ldconfig

make && make install


然后查看gcc/g++, 让其指向新装版本的gcc/g++


有些机器上回报错 /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14'

strings /usr/lib64/libstdc++.so.6 | grep GLIBC 可以发现无3.4.14;

同理将 /usr/lib64/libstdc++.so.6 指向新装的gcc下的libstdc++.so.6!!!直接指向最新的libstdc++.so.6.0.18, 否则有可能运行时会报错GLIBCXX 版本问题



4 安装新版本gdb

安装gdb有可能报错缺少 termcap library

yum -y install ncurses.x86_64

yum -y install ncurses-devel.x86_64


用gdb调试时,会报错 Dwarf Error: wrong version in compilation unit header (is 4, should be 2)

从网上搜到的改 gcc选项无锡哦啊, 看到的栈帧和源代码。

因此安装新版本gdb即可。

wget http://ftp.gnu.org/gnu/gdb/gdb-7.8.tar.gz

解压

./configure && make && make install

















以下是别人笔记







我的环境:CentOS 6.2, kernel 3.1.10  x86_64
需要的配置:Disk space >= 6GB, Mem >= 1GB

从gcc.gnu.org下载gcc-4.8.2.tar.bz2,创建/root/buid-gcc目录,以后所有编译都在这个目录里进行了。
到ftp://gcc.gnu.org/pub/gcc/infrastructure/处下载以下辅助安装包:gmp-4.3.2.tar.bz2, mpfr-2.4.2.tar.bz2, mpc-0.8.1.tar.gz

将以上bz2和gz ball全部放到/root/build-gcc目录下。

1. 编译gmp-4.3.2
展开gmp-4.3.2.tar.bz2:
#tar xf gmp-4.3.2.tar.bz2
#mkdir gmp-build
#cd gmp-build
#../gmp-4.3.2/configure --prefix=/root/rpmbuild/gmp-build 
--build=x86_64-linux
注意:
--build=x86_64-linux选项对于x86_64的平台(比如我用的这个系统)非常重要,否则,无法生成Makefile。
生成Makefile以后,用以下命令编译:
#make
#make check
#make install
这样就把gmp安装到了
/root/build-gcc/gmp-build目录,gmp的安装就完成了,/root/build-gcc/gmp-build目录在将来安装其他包的时候会作为参数被传递。

2. 编译mpfr
#tar xf mpfr-2.4.2.tar.bz2
#mkdir mpfr-build
#cd mpfr-build
#
../mpfr-2.4.2/configure --prefix=/root/build-gcc/mpfr-build/ --with-gmp=/root/build-gcc/gmp-build
#make
#make check
#make install

3.编译mpc
#tar xf mpc-0.8.1.tar.gz
#mkdir mpc-build
#cd mpc-build
#../mpc-0.8.1/configure --prefix=/root/build-gcc/mpc-build/ --with-gmp=/root/build-gcc/gmp-build/ --with-mpfr=/root/build-gcc/mpfr-build/
#make; make check; make install

4.编译GCC
#tar xf gcc-4.7.2.tar.bz2
#mkdir gcc-build
设置LD_LIBRARY_PATH (可选)
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/build-gcc/mpc-build/lib:/root/build-gcc/mpfr-build/lib:/root/build-gcc/gmp-build/lib
创建makefile
#../gcc-4.7.2/configure --prefix=/root/build-gcc/gcc-build/ --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/root/build-gcc/gmp-build/ --with-mpfr=/root/build-gcc/mpfr-build/ --with-mpc=/root/build-gcc/mpc-build/

Build过程中可能出现的错误:
有些包没装(虽然之前已经通过命令#
yum groupinstall "Development Tools" 安装了"Development Tools"),比如ppl和ppl-devel,可能会出现错误:configure: error: cannot compute suffix of object files: cannot compile。查看日志发现错误记录:
conftest.c:10:19: error: ppl_c.h: No such file or directory
conftest.c:16: error: 'choke' undeclared (first use in this function)
conftest.c:16: error: (Each undeclared identifier is reported only once
conftest.c:16: error: for each function it appears in.)
conftest.c:16: error: expected ';' before 'me'
这些错误可以通过命令:
#yum install ppl ppl-devel
安装这两个包来改正。

另外,如果严谨一点, make完后应该要做make -k check的,但是make -k check会报告缺少autogen这个命令,可问题在于CentOS里很难找到这个autogen,所以,马虎点好了,make完后直接make install。

make install完成后,将会在/root/build-gcc/gcc-build/bin目录下生成最终的可执行文件,如gcc,g++这些。而这时,
/root/build-gcc/gcc-build/bin并不存在于PATH中。这就需要将新生成的gcc放到/usr/bin中,让其“可用”了:
#ln -s /root/build-gcc/gcc-build/bin/gcc /usr/bin/gcc-4.7
#ln -s /root/build-gcc/gcc-build/bin/g++ /usr/bin/g++-4.7
注意:以上必须用绝对路径!

其后就可以用gcc-4.7和g++-4.7命令编程序了 
http://blog.csdn.net/foreverdengwei/article/details/8691181


参考的资料: http://blog.csdn.net/sstower/article/details/5624010

http://guliqun1983.blog.163.com/blog/static/50111685201162821716214/

http://www.cnblogs.com/chuncn/archive/2010/10/15/1851853.html


原文:http://chenjiajie.org/post/2012-11-25/40042373551










































































以下是别人的笔记。。。































以下来源于网络。








from http://blog.csdn.net/stormbjm/article/details/9107831

准备工作

  • 下载并解压gcc源码包

    从http://ftp.gnu.org/gnu/gcc 下载一个你想要编译的gcc源码包。 比如下载的是gcc-4.7.2.tar.bz2,然后用输入解压命令 tar -xvf 4.7.2.tar.bz2

  • 安装所需的库

    在使用./configure配置的时候,可能会遇到如下错误: configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.

    这说明需要用到GMP MPFRMPC 这三个库。 传送门:GMP下载MPFR下载MPC下载

    因为MPFR和MPC都依赖于GMP包,所以首先安装GMP。

    $ tar -xvf gmp-5.0.5.tar.bz2

    在Linux下手动编译软件时,要养成建立build目录的好习惯,所以建立一个gmp-5.0.5-build目录

    $ mkdir gmp-5.0.5-build

    $ cd gmp-5.0.5-build

    $./../gmp-5.0.5/configure (可以使用配置参数--prefix=指定安装位置,这里使用默认 /usr/local/include 和/usr/local/lib)

    $make

    $make check (这一步用来确保编译正确)

    $sudo make install

    在执行configure的时候可能会提示错误:checking for suitable m4... configure: error: No usable m4 in $PATH or /usr/5bin

    这就说明我们还要安装m4这个库,传送门:m4

    $ tar -xvf m4-1.4.16.tar.bz2

    $ mkdir m4-1.4.16-build

    $ cd m4-1.4.16-build

    $ ./../m4-1.4.16-build/configure

    $ make

    $ make check

    $ sudo make install

    $ man m4 (如果可以成功man m4,就说明这个库安装成功)

    安装完m4后,我们继续回到之前gmp-5.0.5-build的目录,继续进行configure操作。

    接着安装MPFR这个库

    $ tar -xvf mpfr-3.1.1

    $ mkdir mpfr-3.1.1-build

    $ cd mpfr-3.1.1-build

    $ ./../mpfr-3.1.1/configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib (由于mpfr依赖于gmp这个库,所以在configure时,需要设置好gmp库所在的位置,供安装mpfr库时使用。)

    $ make

    $ make check

    $ sudo make install

    接着安装MPC这个库

    $ tar -xvf mpc-1.0.1

    $ mkdir mpc-1.0.1-build

    $ cd mpc-1.0.1-build

    $ ./../mpc-1.0.1/configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/loca/lib

    $ make

    $ make check

    $ sudo make install

    需要的库都安装完后,为了防止编译gcc时找不到这三个库,所以需要确认库位置是否在环境变量中 LD_LIBRARY_PATH中

    $ echo $LD_LIBRARY_PATH

    如果没有的话,手动添加即可

    $ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"

    为了以后使用的时候不再设置,我们可以修改/etc/bashprofile或者/etc/profile。这里修改的是全局变量,对所有用户有效,修改~/.bashprofile 和~/.profile可以修改用户的全局变量。

    $ sudo vim /etc/profile

    添加以下两句:

    export LD_LIBRARY_PATH=/usr/local/lib

    LD_LIBRARYPATH=:/usr/local/gcc-4.7.2/lib:$LD_LIBRARYPATH

    保存退出

    $ souce /etc/profile

    做完这些准备工作后,就可以开始编译gcc了

  • 构建build目录,开始编译

    $ mkdir gcc-4.7.2-build

    $ cd gcc-4.7.2-build

    接下来要执行configure进行一系列的配置,在[GCC官方网站】(http://gcc.gnu.org/install/configure.html)可以看到一系列的配置。我在编译的时候是参考我机子上原来的配置进行了一点点小改动。

    我在我的终端下使用

    $ gcc -v

    出现了一些列的信息: Target: i686-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5.1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu Thread model: posix gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5.1)

    上面的配置很多,我挑选了几个,最后使用configure配置如下:

    $ ../gcc-4.7.2/configure --prefix=/usr/local/gcc-4.7.2 --enable-threads=posix --disable-checking --enable-languages=c,c++,objc(或者--enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++

    接着执行make

    $ make

    结果遇到错误:gengtype.c:923: undefined reference to `lexer_line'

    按照网上的方法安装一些工具和编译环境: build-essential bison flex

    本来想装个X,用源码安装GCC,没想到又得借助强大的apt-get了 :(

    $ sudo apt-get install build-essential bison flex

    $ make clean (清除下之前没成功编译的文件)

    $ make (继续make)

    又遇到错误:gengtype.c:923: undefined reference to `lexer_line'

    查看build目录下的config.log (查看log真的很有用!),发现问题:conftest.c:10: fatal error: ppl_c.h: No such file or directory

    上网查阅资料,需要安装ppl还有cloog的库.这里有介绍:传送门

    (= = 原谅我再次使用apt-get)

    $ sudo apt-get install libppl0.10-dev

    $ sudo apt-get install libcloog-ppl-dev

    完了之后:

    $ make distclean (make clean和make distclean的区别可以参考:传送门)

    $ make

    这次终于make好了,没有什么错误。保险起见,再

    $ make check

    结果又有错误: /bin/bash: autogen: 未找到命令

    上网查了下,autogen这个库没装,安之!!

    $ sudo apt-get install autogen

    $ make check

    总算是没什么问题了。接着我们

    $ sudo make install

    这步很快就执行完了。 接者我们用gcc -version 查看,版本还是原来的gcc4.4,并没有gcc4.7.2,这是因为gcc4.7.2的可执行文件还没有加入到搜索命令路径中,所以我们要手动加入。

    -添加新版gcc的可执行文件到命令搜索路径中

    首先用which命令查看使用gcc时,系统调用的是哪个路径下的gcc

    $ which gcc

    $ /usr/bin/gcc (说明gcc命令调用的是这个路径下的gcc)

    为此,我们要使用ln命令,建立一个链接,让 /usr/bin/gcc 指向我们安装目录下的gcc. 因为我之前的/usr/bin/gcc已经指向了gcc4.4,所以,先删除这个链接。

    $ sudo rm /usr/bin/gcc

    然后,进行将gcc使用软链接到gcc4.7.2

    $ sudo ln -s /usr/local/gcc-4.7.2/bin/gcc /usr/bin/gcc

    接着,查看下gcc的版本看看有没有成功!

    $ gcc --version

    $ gcc (GCC) 4.7.2 Copyright © 2012 Free Software Foundation, Inc. 本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保; 包括没有适销性和某一专用目的下的适用性担保。

    成功了!我们在用同样的方法重新链接下g++,就能使用g++4.7.2了!

    $ which g++

    $ /usr/bin/g++

    $ sudo rm /usr/bin/g++

    $ sudo ln -s /usr/loca/gcc-4.7.2/bin/g++ /usr/bin/g++

    $ g++ -version

    $ g++ (GCC) 4.7.2 Copyright © 2012 Free Software Foundation, Inc. 本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保; 包括没有适销性和某一专用目的下的适用性担保。

  • 最后,随便编写一个小程序,使用gcc来测试一下吧!

另外一篇:

首先在配置gcc的过程中会出现错误:gcc configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+

说明要安装gcc需要GMP、MPFR、MPC这三个库,可从ftp://gcc.gnu.org/pub/gcc/infrastructure/下载相应的压缩包。由于MPFR依赖GMP,而MPC依赖GMP和MPFR,所以要先安装GMP,其次MPFR,最后才是MPC。这里三个库我用的版本分别是gmp4.3.2,mpfr2.4.2和mpc0.8.1。

先开始安装GMP。解压GMP的压缩包后,得到源代码目录gmp-4.3.2。在该目录的同级目录下建立一个临时的编译目录,这里命名为gmp-build。然后开始配置安装选项,进入gmp-build目录,输入以下命令进行配置:

../gmp-4.3.2/configure --prefix=/usr/local/gmp-4.3.2

这里--prefix选项代表要将该库安装在哪里,我是装在/usr/local/gmp-4.3.2目录下,后面的安装都会用到这个选项。

这时在gmp的编译目录下就会生成一个makefile文件,现在开始编译安装。

make

make check

sudo make install

这样就安装好了gmp。mpfr和mpc的安装方法与此类似。不过要注意配置的时候要把依赖关系选项加进去,具体后面两个库配置命令如下:

../mpfr-2.4.2/configure  --prefix=/usr/local/mpfr-2.4.2 --with-gmp=/usr/local/gmp-4.3.2

../mpc-0.8.1/configure --prefix=/usr/local/mpc-0.8.1 --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2

安装好这三个库之后,就可以正式开始安装gcc了。

与此前一样,先建一个编译gcc的临时目录gcc-build,进入该目录后配置安装选项:

../gcc-4.4.3/configure --prefix=/usr/local/gcc-4.4.3 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2 --with-mpc=/usr/local/mpc-0.8.1

gcc的配置选项有很多,具体可以参考gcc源文件目录下的安装说明。这里只安装了c和c++的编译器。(如果不指定编译的语言,则会在make时不通过,爆出某些文件找不到等错误,所以还是建议在此指定编译语言为c,c++)然后开始make编译。为保险起见,需要在环境变量LD_LIBRARY_PATH添加前面三个库的位置,键入以下命令:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-5.0.1/lib:/usr/local/mpfr-2.4.2/lib

然后重新make编译,在经过漫长的1小时等待后,终于编译完成。在安装说明里面还有测试这一步,不过那是可选的。直接make install安装,至此gcc就全部安装完成了。不过目前还不能使用新版本的gcc,因为新版的可执行文件还没加到命令的搜索路径中。在这里我为新版的gcc和g++命令分别建立了一个软链接。进入/usr/bin目录后,键入如下命令建立软链接。

sudo ln -s /usr/local/gcc-4.4.3/bin/gcc gcc44

sudo ln -s /usr/local/gcc-4.4.3/bin/g++ g++44

这样我使用新版本gcc的时候就可以用gcc44和g++44命令,同时也可使用原来的gcc编译程序。当然这里也可以直接将/usr/bin目录下gcc,g++命令重新链接到新版本的gcc可执行文件。在正式使用之前还有最后一个工作要做,就是将前面安装的三个库的路径加进环境变量LD_LIBRARY_PATH中,不然在编译程序的时候会出错。由于我不想每次编译程序都生成环境变量,所以需要编辑/etc目录下的bashrc文件配置shell环境。在这个文件中添加以下语句:

LD_LIBRARY_PATH=:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/gcc-4.4.3/lib

export LD_LIBRARY_PATH

保存重启系统后,就可以使用新装的gcc了。

以上就是我在CentOS 5.5安装gcc4.4.3的全过程。



出现问题make的时候提示如下:

Checking for suffix of object files... configure: error: in `/home/wulei/sourcecode/gcc-4.6.2/i686-pc-linux-gnu/libgcc':

configure: error: cannot compute suffix of object files: cannot compile

See `config.log' for more details.

make[2]: *** [configure-stage1-target-libgcc] 错误 1

make[2]:正在离开目录 `/home/wulei/sourcecode/gcc-4.6.2'

make[1]: *** [stage1-bubble] 错误 2

make[1]:正在离开目录 `/home/wulei/sourcecode/gcc-4.6.2'

make: *** [all] 错误 2

 

于是 进入/home/wulei/sourcecode/gcc-4.6.2/i686-pc-linux-gnu/libgcc查看这个路径下的config.log

发现如下的错误提示:

/home/wulei/sourcecode/gcc-4.6.2/host-i686-pc-linux-gnu/gcc/cc1: error while loading shared libraries: libmpfr.so.1: cannot open shared ob    ject file: No such file or directory

 

上网查找这个问题

原因是因为linux在make的时候没有自动寻找新加入的库所以要用命令加入

LD_LIBRARY_PATH=/usr/local/mpc-0.8.1/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/gmp-4.3.2/lib

echo $LD_LIBRARY_PATH

export $LD_LIBRARY_PATH



参考:
http://www.comdyn.cn/from-web/68-server-setup/164-centos-48-gcc450.html



1  ftp://gd.tuwien.ac.at/gnu/gcc/releases/gcc-4.8.2/ 下载解压,configure报错, 报错:

configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.Try the --with-gmp, --with-mpfr and/or --with-mpc options to specifytheir locations. 

2 下载/安装三个库; 或者查看 ./contrib/download_prerequisites.sh

tar -xvf gmp-5.0.5.tar.bz2

cd gmp-5.0.5

./configure && make && make check && make install;    头文件在/usr/local/inclue/下, 库在/usr/local/lib/下


wget http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.bz2

tar xvf mpfr-3.1.2.tar.bz2

cd mpfr-3.1.2

./configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib  && make && make install


tar xvf mpc-1.0.tar.gz

cd mpc-1.0

./configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/loca/lib --with-mpfr-include=/usr/local/include --with-mpfr-lib=/usr/local/lib

make && make install


/sbin/ldconfig


3 安装gcc   https://gcc.gnu.org/install/

./configure --prefix=/usr/local/gcc-4.8.2 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local

make;报错

centos 5.4cc1plus: error: unrecognized command line option "-Wno-overlength-strings"g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)man g++没发现有这个选项。 g++版本低肿么办? 好像是4.3加入的这个选项。 得先升到4.3,再升到4.8 ?. 直接去掉这个选项试试(安装成功、程序运行也没多大问题。该选项是和超长字符串有关509)。centos 6.4  64位g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4) 没这问题

configure: error: cannot compute suffix of object files: cannot compile。将依赖库路径加到搜索路径下, /sbin/ldconfig

make && make install


然后查看gcc/g++, 让其指向新装版本的gcc/g++


有些机器上回报错 /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14'

strings /usr/lib64/libstdc++.so.6 | grep GLIBC 可以发现无3.4.14;

同理将 /usr/lib64/libstdc++.so.6 指向新装的gcc下的libstdc++.so.6!!!直接指向最新的libstdc++.so.6.0.18, 否则有可能运行时会报错GLIBCXX 版本问题



4 安装新版本gdb

用gdb调试时,会报错 Dwarf Error: wrong version in compilation unit header (is 4, should be 2)

从网上搜到的改 gcc选项无锡哦啊, 看到的栈帧和源代码。

因此安装新版本gdb即可。

wget http://ftp.gnu.org/gnu/gdb/gdb-7.8.tar.gz

解压

./configure && make && make install

0 0
原创粉丝点击