OSX Loading dylib Lua Module
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开发者_StackOverflow.
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?
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.
package.cpath = package.cpath .. ";?.dylib"
print(package.cpath)
rtn = require ("libme")
print(rtn)
Works just fine on osx.
精彩评论