您的位置:首页 > 运维架构 > Linux

在centos 6.5下面安装gcc 4.1.2

2017-01-08 10:20 555 查看
   因为编译的机器装了centos 6.5,上面的gcc比较新是4.7,而外面运行的机器试centos5.6,所以编译的程序放到上面跑了之后就会出现 /lib64/libc.so.6: version `GLIBC_2.8' not found等错误(就是libc的版本太低,不支持2.8,我们可以用命令 strings /lib64/libc.so.6 | grep GLIBC_来看库支持的版本)。
所以打算在编译的机器上重新装一个4.1.2的gcc。

        安装的基本步骤没什么好说的,就是下载源码 ——》configure ——》 make ——》make install。但是过程却没这么顺利,中间出现了很多问题。
1)configure 没有错误,但make的时候出现 错误
WARNING: `makeinfo' is missing on your system.  You should only need it if

         you modified a `.texi' or `.texinfo' file, or any other file

         indirectly affecting the aspect of the manual.  The spurious

         call might also be the consequence of using a buggy `make' (AIX,

         DU, IRIX).  You might want to install the `Texinfo' package or

         the `GNU make' package.  Grab either from any GNU archive site.

a. 到网上搜索了一下,大部分的解决方案都是说 
configure文件中texinfo对该版本不支持,可以在解压gcc4.1.2文件夹中的configure文件里找到

以下语句

# For an installed makeinfo, we require it to be from texinfo 4.2 or

# higher, else we use the "missing" dummy.

if ${MAKEINFO} --version \

| egrep 'texinfo[^0-9]*([1-3][0-9]|4\.[2-9]|[5-9])' >/dev/null 2>&1; then

:

else

MAKEINFO="$MISSING makeinfo"

fi

;;

其中4\.[2-9]|[5-9]表示的是支持4.2-4.9之间的几个版本,所以需要自己添加4\.[1-9][0-9]*,以支持4.1版本。即把'texinfo[^0-9]*([1-3][0-9]|4\.[2-9]|[5-9])'编辑成'texinfo[^0-9]*([1-3][0-9]|4\.[2-9]|4\.[1-9][0-9]*|[5-9])'后保存,编译通过。

但尝试之后失败

b. 输入命令 makeinfo --version 提示说是没有命令,那么应该是没有这个库,所以下载安装这个库 texinfo 4.7。但在make的时候说是 undefined references to `tputs',然后又查了一下要
先装 ncurses-5.6,于是又下载了安装,这次make texinfo的时候果然OK了。

c. 继续回来安装 gcc,上次的错误这次终于没有了,但又出现一个新才错误 gnu/stubs-32.h: No such file or directory。继续google,重新configure,并增加选项:
./configure --enable-languages=c,c++ --disable-multilib [b]--prefix=/usr/local/gcc412 [/b]
make -j 8
make install
这次成功了。
--enable-languages=c,c++, 表示只要c,c++的gcc,不然什么语言都支持,编译会很耗时

如果不添加--disable-multilib, 那么会出现stub-32.h找不到的错误

而 -j 8使用8个线程来并行编译

实战:
因为要使用淘宝的TFS技术,TFS需要gcc4.1.2,而Centos6.5自带的gcc是4.4.7,所以需要手动编译gcc4.1.2
安装依赖包
yum -y install texinfo

解压
tar zxvf gcc-4.1.2.tar.gz
cd gcc-4.1.2

修改configure文件
egrep 'texinfo[^0-9]*([1-3][0-9]|4\.[1-9]|[1-9])'
修改前

修改后


 

 

编译安装
./configure --disable-checking --disable-multilib --enable-languages=c,c++,java --prefix=/usr/local/gcc412 
make -j4
make install

移除之前的gcc版本
yum remove gcc  
yum remove gcc-c++  

创建新版本的软连接
cd /usr/bin
ln -s /usr/local/gcc412/bin/gcc  gcc
ln -s /usr/local/gcc412/bin/gcc++  g++ 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: