在 Eclipse(Ubuntu 16.04)中使用 luasocket 时出错

我正在尝试在安装了 Ubuntu 16.04 的 Eclipse Luna 中使用 Lua 5.1 和 luasocket。

我已经安装了 Lua 5.1 和 LuaSocket 3.0-rc1,我可以从命令行运行这个程序(lua main.lua):

print(_VERSION)
print("Path: "..package.path..'\nCPATH: '..package.cpath)
socket = require("socket")
print(socket._VERSION)

结果如下:

$ lua main.lua
Lua 5.1
Path: ./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua
CPATH: ./?.so;/usr/local/lib/lua/5.1/?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;/usr/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so
LuaSocket 3.0-rc1

但是当我尝试使用安装了 Lua 插件的 Eclipse 运行相同的程序时,我得到了这个错误:

Lua 5.1
Path: ;./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/media/meslin/16E65872E6585459/Users/meslin/Google Drive/workspace-desktop-ubuntu/Lua Alo Mundo/src/?.lua;/media/meslin/16E65872E6585459/Users/meslin/Google Drive/workspace-desktop-ubuntu/Lua Alo Mundo/src/?/init.lua;/media/meslin/16E65872E6585459/Users/meslin/Google Drive/workspace-desktop-ubuntu/Lua Alo Mundo/src/?.luac;/media/meslin/16E65872E6585459/Users/meslin/Google Drive/workspace-desktop-ubuntu/Lua Alo Mundo/src/?/init.luac;
CPATH: ./?.so;/usr/local/lib/lua/5.1/?.so;/usr/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so
Exception in thread "main" com.naef.jnlua.LuaRuntimeException: error loading module 'socket.core' from file '/usr/local/lib/lua/5.1/socket/core.so':
/usr/local/lib/lua/5.1/socket/core.so: undefined symbol: lua_gettop
    at com.naef.jnlua.LuaState.lua_pcall(Native Method)
    at com.naef.jnlua.LuaState.call(LuaState.java:555)
    at org.eclipse.ldt.support.lua51.internal.interpreter.JNLua51Launcher.run(JNLua51Launcher.java:128)
    at org.eclipse.ldt.support.lua51.internal.interpreter.JNLua51Launcher.main(JNLua51Launcher.java:143)

有什么想法吗?能帮帮我吗?

谢谢 Alexandre

点赞
用户1442917
用户1442917

同样的问题在一段时间前已经在 lua 的邮件列表 上讨论过了,看看那里的建议是否能帮到你:

默认情况下,LDT 附带了一个内置的 Lua VM(基于 jnLua),因此任何人都可以立即开始运行 Lua 脚本,甚至不需要在其计算机上安装 Lua。我想你设置 PATH 和 CPATH 的方式使得 jnLua VM 无法再被找到了。

你可能想要为本地本机 VM 配置一个“本地解释器”。你可以参考 [1]。一旦你设置了解释器,你可以通过调整启动配置来针对这个解释器而不是嵌入式的 jnLua 运行脚本。

2017-04-10 20:47:24