从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自动下载了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的安装文件列表