mac如何升级g++的版本?更改默认gcc版本

本文主要参考知乎的答案(https://zhihu.com/question/35215099/answer/63559664)


1. 安装port: 在port官网中选择一个适合自己系统的版本下载


2. 安装后,进入port目录,我没有修改默认安装路径,port所在位置为:


/opt/local/bin

3. 查找gcc库:


./port search gcc #查找gcc库
我的显示如下,显示的其实挺多的,上下翻看一下所需的版本:

4. 安装gcc4.8

sudo -i #获取管理员权限
#键入密码
./port install gcc49


5. 查看安装的版本

./port select --list gcc


6. 切换版本

sudo ./port select --set gcc mp-gcc49


7. 清空bash缓存

hash -r

在新的命令行窗口中查看gcc/g++版本:

UserName:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin16/4.9.4/lto-wrapper
Target: x86_64-apple-darwin16
Configured with: /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_gcc49/gcc49/work/gcc-4.9.4/configure --prefix=/opt/local --build=x86_64-apple-darwin16 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc49 --includedir=/opt/local/include/gcc49 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.9 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.9 --with-gxx-include-dir=/opt/local/include/gcc49/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local --disable-isl-version-check --with-cloog=/opt/local --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-build-config=bootstrap-debug --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc49 4.9.4_1' --with-build-config=bootstrap-debug
Thread model: posix
gcc version 4.9.4 (MacPorts gcc49 4.9.4_1) 

如果本文对您有用,点个赞呗大笑





  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值