在lua中用下面這種方式使用socket,安裝luasocket-2.0.2後總是報一些莫名其妙的錯誤。linux
require("socket")
下面是部分報錯信息shell
lua: error loading module 'socket.core' from file '/usr/local/lib/lua/5.3/socket/core.so': /usr/local/lib/lua/5.3/socket/core.so: undefined symbol: luaL_checkint stack traceback: [C]: in ? [C]: in function 'require' /usr/local/share/lua/5.3/socket.lua:13: in main chunk [C]: in function 'require' /usr/local/share/lua/5.3/socket/http.lua:11: in main chunk [C]: in function 'require' bb.lua:2: in main chunk [C]: in ?
在網上找了一篇博文寫的不錯,博文地址 ,可是按照博文修改源碼後依然不能解決問題socket
又Google了一篇文章寫的更好,從根本解決上解決了問題博文地址 感謝!ui
順便在luajit-2.0.4(生產環境版本)試了一下第二種方式,在編譯時會報錯以下lua
luasocket.c:18:17: fatal error: lua.h: No such file or directory compilation terminated. <builtin>: recipe for target 'luasocket.o' failed make[2]: *** [luasocket.o] Error 1 make[2]: Leaving directory '/tmp/luasocket/src' makefile:359: recipe for target 'linux' failed make[1]: *** [linux] Error 2 make[1]: Leaving directory '/tmp/luasocket/src' makefile:18: recipe for target 'linux' failed make: *** [linux] Error 2
問題緣由是make時找不到lua.h頭文件,編譯時本身手動指定頭文件路徑LUAINC=/usr/local/luajit/include/luajit-2.0,以下.net
make LUAINC=/usr/local/luajit/include/luajit-2.0 make install
ENDcode