OSX loading the dylib Lua module

When I try to load the Lua module on OSX, I get 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 the .so file, not the .dylib file. I got the impression that .dylib is the equivalent of OSX (with slight modifications) .so. Therefore, I expect the Lua interpreter to look for the .dylib file.

Should I try to compile my library in .so on OSX? (If so?) Or do I need to change something related to the lua interpreter?

+4
source share
2 answers

No need to change the interpreter (provided that .dynlib loads (according to Lua Programming, chapter 26 )). You can modify package.cpath to search for .dynlibs instead of .so before requiring a module.

+5
source
 package.cpath = package.cpath .. ";?.dylib" print(package.cpath) rtn = require ("libme") print(rtn) 

Works fine on osx.

0
source

All Articles