• linux安装gcc4.6.1


    linux安装gcc4.6.1

    事情的起因是因为启动某个执行文件时报错,关键信息如下:/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.11’ not found;网上查询到的原因就是gcc的版本比较低,所以我们考虑升级一下gcc;

    gcc的下载目录选择https://mirrors.aliyun.com/gnu/gcc,可选择比较多,我这里下载了gcc-4.6.1.tar.gz这个包;这里有个坑,需要注意先安装三个依赖:gmp,mprf,mpc;

    一个是mpc,一个是gmp,一个是mpfr,下载地址依次为:ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz,ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.bz2 ,http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.2.tar.gz。安装的顺序依次为:gmp,mpfr, mpc,最后安装gcc。

    安装GMP

    命令如下

    tar -jxvf gmp-5.0.1.tar.bz2
    cd gmp-5.0.1
    mkdir temp
    cd temp
    
    ../configure --prefix=/usr/local/gmp-5.0.1
    make
    make install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    mkdir temp是建立一个编译目录,执行…/configure --prefix=/usr/local/gmp-5.0.1此步之后,temp文件夹内已经产生makefile文件,执行make就会开市进行编译,/usr/local/gmp-5.0.1是安装目录,会自动生成;

    安装mprf

    tar -zxvf mpfr-3.1.2.tar.gz
    cd mpfr-3.1.2
    mkdir temp
    cd temp
    
    ../configure --prefix=/usr/local/mpfr-3.1.0 --with-gmp=/usr/local/gmp-5.0.1
    make
    make install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    执行…/configure --prefix=/usr/local/mpfr-3.1.0 --with-gmp=/usr/local/gmp-5.0.1时,–prefix后面是mpfr的安装目录,–with-gmp是依赖gmp的目录,所以要先安装gmp。

    安装mpc

    tar -zxvf mpc-1.0.2.tar.gz
    cd mpc-1.0.2
    mkdir temp
    cd temp
    
    ../configure --prefix=/usr/local/mpc-1.0.2 --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.0
    make
    make install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    –with后面都是依赖的目录;

    安装gcc

    安装之前,注意这里有一个小坑,添加LD_LIBRARY_PATH,否则可能会报错,
    checking for suffix of object files... configure: error: in /root/gcc-4.6.1/temp/i686-pc-linux-gnu/libgcc': configure: error: cannot compute suffix of object files: cannot compile
    这时候就注意要添加这个环境变量

    export LD_LIBRARY_PATH=/usr/local/mpc-1.0.2/lib:/usr/local/mpfr-3.1.0/lib;/usr/local/gmp-5.0.1/lib
    
    • 1

    然后执行下面的脚本进行安装

    tar zxvf gcc-4.6.1.tar.gz
    cd gcc-4.6.1
    mkdir temp
    cd temp
    
    ../configure --prefix=/usr/local/gcc-4.6.1 --enable-threads=posix --disable-checking --enable--long-long --enable-languages=c,c++,java --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.0 --with-mpc=/usr/local/mpc-1.0.2
    make -j4
    make install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    make -j4 会启用4个线程,但是还是会耗时比较久,至少要编译1个小时;

    更新gcc

    使用以下命令更新gcc 版本

    mv /usr/bin/gcc /usr/bin/gcc461
    mv /usr/bin/g++ /usr/bin/g++461
    mv /usr/bin/c++ /usr/bin/c++461
    mv /usr/bin/cc /usr/bin/cc461
     
     
    ln -s /usr/local/gcc-4.6.1/bin/gcc /usr/bin/gcc
    ln -s /usr/local/gcc-4.6.1/bin/g++ /usr/bin/g++
    ln -s /usr/local/gcc-4.6.1/bin/c++ /usr/bin/c++
    ln -s /usr/local/gcc-4.6.1/bin/gcc /usr/bin/cc
     
     
    mv /usr/lib/libstdc++.so.6 /usr/lib/libstdc++.so.6.bak
    ln -s /usr/local/gcc-4.6.1/lib/libstdc++.so.6.0.16 /usr/lib/libstdc++.so.6
    
    gcc -v 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    以上的一些lib库要根据系统来,lib或者lib64根据本地的文件夹来判断

  • 相关阅读:
    安装Photon虚拟机
    Unity WebGL 播放视频流m3u8
    java毕业设计选题基于SSM项目源码实现的校园食堂点餐|订餐系统
    Elasticsearch介绍及插件head和kibana下载
    机器学习强基计划0-3:数据集核心知识串讲,构造方法解析
    Android | ArcGIS入门
    ESP32 Arduino实战协议篇-搭建独立的 Web 服务器
    并发编程(三)---共享模型之管程
    ES聚合统计
    【C语言】柔性数组
  • 原文地址:https://blog.csdn.net/qq_27577503/article/details/126243473