mac用homebrew安装gcc

从luajit官网下载了LuaJIT-2.1.0-beta3源码,编译的时候报错:

banxia:LuaJIT-2.1.0-beta3 $ make
==== Building LuaJIT 2.1.0-beta3 ====
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C src
In file included from /usr/local/gcc-6.2.0/lib/gcc/x86_64-apple-darwin16.1.0/6.2.0/include-fixed/syslimits.h:7:0,
                 from /usr/local/gcc-6.2.0/lib/gcc/x86_64-apple-darwin16.1.0/6.2.0/include-fixed/limits.h:34,
                 from luaconf.h:12,
                 from lua.h:16,
                 from lj_arch.h:9:
/usr/local/gcc-6.2.0/lib/gcc/x86_64-apple-darwin16.1.0/6.2.0/include-fixed/limits.h:168:61: 致命错误:limits.h:No such file or directory
 #include_next <limits.h>  /* recurse down to the real one */
                                                             ^

OS是macOS High Sierra 10.13.5,gcc版本是6.2.0。

banxia:LuaJIT-2.1.0-beta3 $ sw_vers 
ProductName:    Mac OS X
ProductVersion: 10.13.5
BuildVersion:   17F77

banxia:LuaJIT-2.1.0-beta3 $ gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-6.2.0/libexec/gcc/x86_64-apple-darwin16.1.0/6.2.0/lto-wrapper
目标:x86_64-apple-darwin16.1.0
配置为:../configure --prefix=/usr/local/gcc-6.2.0 --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.4 --with-mpc=/usr/local/mpc-1.0.3 --disable-multilib --with-sytem-zlib --enable-languages=c,c++
线程模型:posix
gcc 版本 6.2.0 (GCC) 

gcc是几年前为了试用c++11装的,估计是gcc或者libc没有装好。于是要重装gcc,突然想到一直想试用homebrew却没有用过,正好用用看。
于是,在homebrew官网上拷贝一条ruby命令到终端上:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

执行上述命令后,脚本会先安装Command Line Tools,然后再从github上下载homebrew,最后会提示安装成功。安装的homebrew版本是1.6.9:


==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics.html

==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh

banxia:LuaJIT-2.1.0-beta3 $ brew --version
Homebrew 1.6.9
Homebrew/homebrew-core (git revision 08dacaf; last commit 2018-07-04)

下一步,安装gcc

banxia:LuaJIT-2.1.0-beta3 $ brew search gcc
==> Searching local taps...
apple-gcc42  gcc          gcc@4.9      gcc@5        gcc@6        gcc@7
banxia:LuaJIT-2.1.0-beta3 $ brew install gcc@7
Error: Your Xcode (8.1) is too outdated.
Please update to Xcode 9.4 (or delete it).
Xcode can be updated from the App Store.

gcc最新版本已经到8.1了,brew才到7。算了吧,装gcc7,又提示xcode版本太旧。按提示的方法,在app store上升级xcode到9.4。
等了几个小时后,xcode装好。继续装gcc:

brew install gcc.png

brew自动下载了gcc依赖的四个库。
brew运行执行的脚本或者命令会实时刷新到终端顶部的标题栏。如果brew卡住不动,可以看看标题栏,brew正在做什么。
下载并安装完依赖库后,安装gcc,最后会提示gcc安装在/usr/local/Cellar/gcc@7目录下。

==> Pouring isl-0.19.high_sierra.bottle.tar.gz
  /usr/local/Cellar/isl/0.19: 66 files, 3.8MB
==> Installing gcc@7 dependency: mpfr
==> Downloading https://homebrew.bintray.com/bottles/mpfr-4.0.1.high_sierra.bott
######################################################################## 100.0%
==> Pouring mpfr-4.0.1.high_sierra.bottle.tar.gz
  /usr/local/Cellar/mpfr/4.0.1: 28 files, 4.6MB
==> Installing gcc@7 dependency: libmpc
==> Downloading https://homebrew.bintray.com/bottles/libmpc-1.1.0.high_sierra.bo
######################################################################## 100.0%
==> Pouring libmpc-1.1.0.high_sierra.bottle.tar.gz
  /usr/local/Cellar/libmpc/1.1.0: 12 files, 353.9KB
==> Installing gcc@7
==> Downloading https://homebrew.bintray.com/bottles/gcc@7-7.3.0.high_sierra.bot
######################################################################## 100.0%
==> Pouring gcc@7-7.3.0.high_sierra.bottle.tar.gz
  /usr/local/Cellar/gcc@7/7.3.0: 1,486 files, 285.3MB

安装时提示权限不够

Error: The following directories are not writable by your user:
/usr/local/share/man/man5

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/share/man/man5

如果sudo brew会失败,提示这样操作非常危险

$ sudo brew install gcc@7
Password:
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

所以还是按brew的建议sudo目录。

但是用gcc -v查gcc版本还是6.2,什么情况?
查brew的安装列表,gcc7已经装了啊。

banxia:LuaJIT-2.1.0-beta3 yangjia$ brew list
gcc@7       isl     mpfr        springboot
gmp     libmpc      sbt

发现/usr/local/bin下多了几个gcc-7的bin:

banxia:bin $ ls -l gcc*
lrwxr-xr-x  1 root     wheel  28 11 24  2016 gcc -> /usr/local/gcc-6.2.0/bin/gcc
lrwxr-xr-x  1 somebody  admin  31  7  5 02:37 gcc-7 -> ../Cellar/gcc@7/7.3.0/bin/gcc-7
lrwxr-xr-x  1 somebody  admin  34  7  5 02:37 gcc-ar-7 -> ../Cellar/gcc@7/7.3.0/bin/gcc-ar-7
lrwxr-xr-x  1 somebody  admin  34  7  5 02:37 gcc-nm-7 -> ../Cellar/gcc@7/7.3.0/bin/gcc-nm-7
lrwxr-xr-x  1 somebody  admin  38  7  5 02:37 gcc-ranlib-7 -> ../Cellar/gcc@7/7.3.0/bin/gcc-ranlib-7

brew装的gcc就是gcc-7

banxia:bin $ gcc-7 -v
Using built-in specs.
COLLECT_GCC=gcc-7
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc@7/7.3.0/libexec/gcc/x86_64-apple-darwin17.5.0/7.3.0/lto-wrapper
Target: x86_64-apple-darwin17.5.0
Configured with: ../configure --build=x86_64-apple-darwin17.5.0 --prefix=/usr/local/Cellar/gcc@7/7.3.0 --libdir=/usr/local/Cellar/gcc@7/7.3.0/lib/gcc/7 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-7 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-checking=release --with-pkgversion='Homebrew GCC 7.3.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-nls
Thread model: posix
gcc version 7.3.0 (Homebrew GCC 7.3.0) 

最后再用gcc-7编译luajit,一切正常:

banxia:LuaJIT-2.1.0-beta3 $ make "CC=gcc-7"
==== Building LuaJIT 2.1.0-beta3 ====
/Library/Developer/CommandLineTools/usr/bin/make -C src
HOSTCC    host/minilua.o
。。。。。
CC        lib_init.o
AR        libluajit.a
CC        luajit.o
BUILDVM   jit/vmdef.lua
DYNLINK   libluajit.so
LINK      luajit
OK        Successfully built LuaJIT
==== Successfully built LuaJIT 2.1.0-beta3 ====

brew命令总结

  • brew --version # 查询brew版本号
  • brew search xxx # 搜索xxx的安装版本信息
  • brew install yyy # 安装yyy,一般是软件名+版本的形式
  • brew uninstall yyy # 卸载yyy
  • brew list # 输出已安装的软件列表
  • brew list yyy # 输出yyy的安装文件列表
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,165评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,720评论 1 298
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,849评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,245评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,596评论 3 288
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,747评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,977评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,708评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,448评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,657评论 2 249
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,141评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,493评论 3 258
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,153评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,108评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,890评论 0 198
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,799评论 2 277
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,685评论 2 272

推荐阅读更多精彩内容