Linux
在CenOS 7.9中自带的GCC版本为4.8.5,是2015年的版本,太过久远。(尝试当前最新版本14.2.0未成功,在make时出错,尝试了网上看到的9.3.0版本,下面用这个版本)
http://ftp.gnu.org/gnu/gcc/找到9.3.0
进入后,右键 gcc-9.3.0.tar.gz的一项右键复制链接
在终端中依次执行
wget http://ftp.gnu.org/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
tar -xvzf gcc-9.3.0.tar.gz
cd gcc-9.3.0
./contrib/download_prerequisites
# /usr/local/gcc-9.3.0/为安装的路径,可以修改
./configure --prefix=/usr/local/gcc-9.3.0/ --enable-bootstrap --enable-checking=release --disable-multilib
make #编绎,大约需要10~30分钟
当make结束后,最后面是:
make[4]: Leaving directory `/data/gcc-9.3.0/x86_64-pc-linux-gnu/libatomic'
make[3]: Leaving directory `/data/gcc-9.3.0/x86_64-pc-linux-gnu/libatomic'
make[2]: Leaving directory `/data/gcc-9.3.0/x86_64-pc-linux-gnu/libatomic'
make[1]: Leaving directory `/data/gcc-9.3.0'
大概是这样的内容,就是成功的,然后执行
make install
安装很快
配置环境变量
#下面的路径就是上面执行configure时的路径加上/bin
echo 'export PATH=/usr/local/gcc-9.3.0/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
完成后,输入验证版本
gcc --version
添加动态库路径
echo "/usr/local/gcc-9.3.0/lib64" > /etc/ld.so.conf.d/gcc-9.3.0.conf
ldconfig
Windows
https://www.gnu.org/software/gcc/
右侧菜单中点击Binaries
Installation: GitHub
目前最新版中的GCC版本为:14.2.0