OSX 加载 dylib Lua 模块
当尝试在 OSX 上加载 Lua 模块时,我收到以下错误。
lua: level1.lua:1: module 'libexpand_luaLib' not found:
no field package.preload['libexpand_luaLib']
no file './libexpand_luaLib.lua'
no file '/opt/local/share/lua/5.1/libexpand_luaLib.lua'
no file '/opt/local/share/lua/5.1/libexpand_luaLib/init.lua'
no file '/opt/local/lib/lua/5.1/libexpand_luaLib.lua'
no file '/opt/local/lib/lua/5.1/libexpand_luaLib/init.lua'
no file './libexpand_luaLib.so'
no file '/opt/local/lib/lua/5.1/libexpand_luaLib.so'
no file '/opt/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
level1.lua:1: in main chunk
[C]: ?
lua 解释器正在尝试加载 .so 文件而不是 .dylib 文件。我的印象是 .dylib 是 .so 的 OSX 等效项(略有变化)。所以我希望 Lua 解释器寻找 .dylib 文件。
我应该尝试将我的库编译成 OSX 上的 .so 吗?(如果是的话怎么办?)或者我应该更改与 lua 解释器相关的内容?
When trying to load a Lua module on OSX I receive the following error.
lua: level1.lua:1: module 'libexpand_luaLib' not found:
no field package.preload['libexpand_luaLib']
no file './libexpand_luaLib.lua'
no file '/opt/local/share/lua/5.1/libexpand_luaLib.lua'
no file '/opt/local/share/lua/5.1/libexpand_luaLib/init.lua'
no file '/opt/local/lib/lua/5.1/libexpand_luaLib.lua'
no file '/opt/local/lib/lua/5.1/libexpand_luaLib/init.lua'
no file './libexpand_luaLib.so'
no file '/opt/local/lib/lua/5.1/libexpand_luaLib.so'
no file '/opt/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
level1.lua:1: in main chunk
[C]: ?
The lua interpreter is trying to load a .so file and not a .dylib file. I was under the impression that .dylib is the OSX equivalent(with slight changes) of .so. So I'd expect the Lua interpreter to be looking for a .dylib file.
Should I be trying to compile my library into a .so on OSX?(If so how?) Or should I be changing something related to the lua interpreter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需更改解释器(前提是 .dynlib 是可加载的(按照 Lua 编程,第 26 章) )。
在需要该模块之前,您可以更改 package.cpath 以查找 .dynlibs 而不是 .so。
No need to change the interpreter (provided that the .dynlib is loadable (as per Programming in Lua, chapter 26 )).
You can change the package.cpath to look for .dynlibs instead of .so's, before requiring the module.
在 osx 上运行得很好。
Works just fine on osx.