mac 安装 luasocket

mac lua版本已经升级到5.3,通过luarocks install luasocket一直失败,无法安装,于是选择手工安装

1.下载并编译安装luasocket安装包

$git clone https://github.com/diegonehab/luasocket.git
$sudo make
/Library/Developer/CommandLineTools/usr/bin/make -C src linux
/Library/Developer/CommandLineTools/usr/bin/make all-unix PLAT=linux
gcc  -I/usr/include/lua/5.1 -I/usr/include/lua5.1 -DLUASOCKET_NODEBUG -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic   -c -o luasocket.o luasocket.c
In file included from luasocket.c:15:
./luasocket.h:27:10: fatal error: 'lua.h' file not found
#include "lua.h"
         ^~~~~~~
1 error generated.
make[2]: *** [luasocket.o] Error 1
make[1]: *** [linux] Error 2
make: *** [linux] Error 2

编译时未找到lua.h文件,系统中安装的是lua5.3,修改编译参数

$sudo make LUAINC=-I/usr/local/Cellar/lua/5.3.5_1/include/lua macosx
$sudo make install

/Library/Developer/CommandLineTools/usr/bin/make -C src install
install -d /usr/local/share/lua/5.1
install -m644 ltn12.lua socket.lua mime.lua /usr/local/share/lua/5.1
install -d /usr/local/share/lua/5.1/socket
install -m644 http.lua url.lua tp.lua ftp.lua headers.lua smtp.lua /usr/local/share/lua/5.1/socket
install -d /usr/local/lib/lua/5.1/socket
install socket-3.0-rc1.so /usr/local/lib/lua/5.1/socket/core.so
install -d /usr/local/lib/lua/5.1/mime
install mime-1.0.3.so /usr/local/lib/lua/5.1/mime/core.so

2.测试验证

¥lua
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
> require("socker")
stdin:1: module 'socker' not found:
	no field package.preload['socker']
	no file '/usr/local/share/lua/5.3/socker.lua'
	no file '/usr/local/share/lua/5.3/socker/init.lua'
	no file '/usr/local/lib/lua/5.3/socker.lua'
	no file '/usr/local/lib/lua/5.3/socker/init.lua'
	no file './socker.lua'
	no file './socker/init.lua'
	no file '/usr/local/lib/lua/5.3/socker.so'
	no file '/usr/local/lib/lua/5.3/loadall.so'
	no file './socker.so'
stack traceback:
	[C]: in function 'require'
	stdin:1: in main chunk
	[C]: in ?

由于安装路径默认安装路径与lua查找文件路么不一径,尝试INSTALL_TOP_SHARE 和INSTALL_TOP_LIB重新安排,仍未成功,

于是手工修拷备

$cd  /usr/local/share/lua

$sudo cp -R 5.1 5.3

$cd /usr/local/lib/lua 

$sudo cp   -R 5.1 5.3

3.再次验证

$ lua
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
> require("socket")
table: 0x7fd7c1c03ad0
>

验证成功

你可能感兴趣的:(lua)