修改mac默认的gcc到自己安装的gcc

来源:互联网 发布:淘宝首页导航尺寸 编辑:程序博客网 时间:2024/05/24 05:55

我使用homebrew安装了最新版的gcc,但是gcc --version还是之前系统自带的gcc,版本是4.2.1

原来我新装的gcc的名字变成了gcc-7

➜  ~ gcc-7 --versiongcc-7 (Homebrew GCC 7.1.0) 7.1.0Copyright (C) 2017 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
想使用gcc-7代替系统自带gcc的方法:

vim ~/.bash_profile

在文件中追加如下几行:

alias gcc='gcc-7'alias g++='g++-7'alias c++='c++-7'

然后运行命令:source ~/.bash_profile

大功告成:

➜  ~ gcc-7 --versiongcc-7 (Homebrew GCC 7.1.0) 7.1.0Copyright (C) 2017 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.




原创粉丝点击