1. 程式人生 > >lua相關庫安裝常見問題

lua相關庫安裝常見問題

ash res 報錯 技術分享 lar .org 版本 成功 ould

一、先安裝lua

brew install lua

我本機的安裝路徑為:/usr/local/Cellar/lua/5.3.4_2

二、安裝luarocks

下載luarocks的安裝包:

http://luarocks.github.io/luarocks/releases/luarocks-2.4.3.tar.gz

解壓後到安裝包的目錄下執行如下命令(可以自行根據自己的lua版本號進行修改):

./configure --with-lua=/usr/local/Cellar/lua/5.3.4_2 --with-lua-include=/usr/local/Cellar/lua/5.3.4_2/include

make

make
install

安裝完成

參考鏈接:http://www.shixinke.com/openresty/openresty-lua-luarocks

三、安裝lfs

sudo luarocks install luafilesystem

技術分享圖片

可能會有報錯,but,anyway,安裝成功了不是麽

lfs的使用:

進入到lua的命令行,require "lfs"

技術分享圖片

大功告成,可以正常使用了

引用鏈接:https://luarocks.org/

四、安裝luasocket和luasql

1、首先安裝luasocket

sudo luarocks install luasocket

2、安裝luasql

我遇到了下面的問題

Warning: The directory /Users/baidu/.cache/luarocks or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing /usr/local/bin/luarocks with sudo, you may want sudos -H flag.
Warning: falling back to curl - install luasec to get
native HTTPS support Installing https://luarocks.org/luasql-mysql-2.3.5-1.rockspec Error: Could not find header file for MYSQL No file mysql.h in /usr/local/include No file mysql.h in /usr/include You may have to install MYSQL in your system and/or pass MYSQL_DIR or MYSQL_INCDIR to the luarocks command.
Example: luarocks install luasql-mysql MYSQL_DIR=/usr/local

看錯誤提示,是沒有找到mysql的頭文件,需要先安裝一下mysql:

mac執行下面brew install mysql命令即可安裝。根據終端的打印結果,發現mysql的安裝目錄為/usr/local/Cellar/mysql/5.7.21。

那繼續找上面的問題:

上面的報錯提示可以用下面的命令進行安裝:luarocks install luasql-mysql MYSQL_DIR=/usr/local

不過我們的MYSQL_DIR是目錄:/usr/local/Cellar/mysql/5.7.21

所以我們改一下報錯提示中的安裝命令:

sudo luarocks install luasql-mysql MYSQL_INCDIR=/usr/local/Cellar/mysql/5.7.21/include/mysql

好了,出現下面的日誌,安裝成功了:

技術分享圖片

lua相關庫安裝常見問題