您的位置:首页 > 其它

ubuntu10.4系统下GCC降级安装

2014-01-06 10:16 337 查看
ubuntu10.4环境下默认的GCC版本为4.4.3,由于编译环境的GCC版本为3.2.2,想在ubuntu上使用编译环境版本的GCC,故需要将GCC版本降级到3.2.2。GCC在新版本加入了一些高级特性,导致从GCC4.4.3不能直接降级到3.2.2。本文通过尝试,可以通过阶段性的降级方案,即先从GCC4.4.3降级到 GCC3.4.4版本,再从GCC3.4.4降级到GCC3.2.2。以下是重要的操作步骤和过程中问题的解决方法。(1)可以在http://gcc.gnu.org/网站,通过任何一个镜像站点来下载GCC3.4.4版本和GCC3.2.2版本,本文的下载路径为ftp://gd.tuwien.ac.at/gnu/gcc/releases /gcc-3.4.4/gcc-3.4.4.tar.bz2和ftp://gd.tuwien.ac.at/gnu/gcc/releases/gcc- 3.2.2/gcc-3.2.2.tar.bz2。(2)安装GCC3.4.4。首先在编译环境下执行gcc –v来获取GCC的configure信息,本文中其结果为:xxx/ABC /home/xxx # gcc -vReadingspecs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specsConfigured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linuxThread model: posixgcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)在降级的设备上将gcc-3.4.4.tar.bz2解压之后进入解压目录,参考编译环境中GCC的配置来配置当前的GCC3.4.4。./configure --prefix=/usr/local/gcc-3.4.4/ --mandir=/usr/local/gcc-3.4.4/share/man --infodir=/usr/local/gcc-3.4.4/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --enable-languages=c,c++其中的prefix、mandir、infodir都可以根据自己的需要来设置,configure之后执行make && make install。其中在make的过程中会出现以下错误:www.it165.netIn function 'open',inlined from 'collect_execute' at ./collect2.c:1537:/usr/include/bits/fcntl2.h:51: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments解决的方法是修改gcc/collect2.c的1537行,将原来的redir_handle = open (redir, O_WRONLY | O_TRUNC | O_CREAT);修改为redir_handle = open (redir, O_WRONLY, O_TRUNC | O_CREAT);即将原来open调用中的2个参数修改为3个参数,然后重新进行make和make install即可完成GCC3.4.4的安装,(3)为了在某些场景下继续使用GCC4.4.3可以通过以下方式保留GCC4.4.3,方法是在gcc的安装路径/usr/bin/目录下按照以下步骤操作。mv gcc gcc-4.4.3mv g++ g++-4.4.3ln –s /usr/local/gcc-3.4.4/bin/gcc gccln –s /usr/local/gcc-3.4.4/bin/g++ g++这样GCC4.4.3和GCC3.4.4就可以共同存在了。(4)安装了GCC3.4.4,还要修改/etc/bash.bashrc在其末尾增加以下内容,以让其正确链接到它需要的库。LD_LIBRARY_PATH=/usr/local/ gcc-3.4.4/libexport LD_LIBRARY_PATH通过以上操作重新source /etc/bash.bashrc后就可以使用gcc3.4.4了。(5)同样按照上面的方法可以在GCC3.4.4的基础上安装GCC3.2.2,所不同的是在configure的过程中需要指定不同的安装路径。安装完成之后执行gcc –v可以看到以下输出。root@xxx-desktop:/usr/local/gcc-3.4.4/bin# gcc -vReadingspecs from /usr/local/gcc-3.2.2//lib/gcc-lib/i686-pc-linux-gnu/3.2.2/specsConfigured with: ./configure --prefix=/usr/local/gcc-3.2.2/ --mandir=/usr/local/gcc-3.2.2/share/man --infodir=/usr/local/gcc-3.2.2/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --enable-languages=c,c++Thread model: posixgcc version 3.2.2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: