Aliases:gcc 非管理员升级版本
Tags: 服务器
date: 2023-04-15
由于现阶段,集群的 gcc4.x 版本已经不能满足自己的需求,但是由于项目要求大于5.x 的 gcc 版本,所以又不得不升级。
报错如下:
RuntimeError: The current installed version of g++ (4.8.5) is less than the minimum required version by CUDA 11.4 (6.0.0). Please make sure to use an adequate version of g++ (>=6.0.0, <=10.0.0).
[end of output]
1.官网下载 gcc9.4的压缩包
https://ftp.gnu.org/gnu/gcc/gcc-9.4.0/gcc-9.4.0.tar.gz
2.tar -xzf 命令解压
tar -xzf gcc-9.4.0.tar.gz
这个会将压缩包解压到当前目录
3.新建文件夹,安装 gcc(在当前目录新建,官网新建的目录名为 objdir,我换了个名)
mkdir gcc-9.4.0-build
cd gcc-9.4.0-build
需要在gcc-9.4.0-build文件夹中执行命令,安装gcc包
../configure --disable-checking --enable-languages=c,c++,fortran --disable-multilib --prefix=/path/to/install/gcc-9.4 --enable-threads=posix
prefix=/path/to/install/gcc-9.4是自己定义要安装GCC的目录,更改成你的目录就可以 prefix=/path/to/install/gcc-9.4这个参数
PS: 我遇到了一个问题就是我没有在gcc-9.4.0里新建gcc-9.4.0-build这个包,而是新建在外面的(也就是其他目录),最后报错了,所以最好是在这里建。也许在外面建也行,但是编译的时候估计得用软连接连接一下,技术好的自己尝试啦。
4.编译环境并安装
编译:
make -j
如果后面加数字代表选择核心数
如: make -j4,表示选择4个核心去编译,自己选择就好,默认不写我这也没问题
安装:
make install
PS: 编译的时间特别长,耐心等待,尽量别中断,以免带来其他问题
5.添加环境变量
-
export PATH=/path/to/install/gcc-9.4/bin:$PATH
-
export LD_LIBRARY_PATH=/path/to/install/gcc-9.4/lib/:/path/to/install/gcc-9.4/lib64:$LD_LIBRARY_PATH
如我的:
export PATH=/public/home/mcao/usr/xy/source/gcc/bin:$PATH
export LD_LIBRARY_PATH=/public/home/mcao/usr/xy/source/gcc/lib/:/public/home/mcao/usr/xy/source/gcc/lib64/:$LD_LIBRARY_PATH
6.参考:
http://bbs.06climate.com/forum.php?mod=viewthread&tid=87904
http://bbs.06climate.com/forum.php?mod=viewthread&tid=87904
https://blog.csdn.net/weixin_42054508/article/details/106468768