2011-05-05 1 views
3

OSX에서 Lua 모듈을로드 할 때 다음 오류가 발생합니다.OSX dylib 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 인터프리터는 .dylib 파일이 아닌 .so 파일을로드하려고합니다. 나는 .dylib가 .so의 (약간의 변경과 함께) OSX와 동일하다는 인상하에 있었다. 그래서 루아 통역사가 .dylib 파일을 찾을 것으로 기대합니다.

내 라이브러리를 OSX에서 .so로 컴파일해야합니까? (그렇다면 어떻게됩니까?) 아니면 루아 인터프리터와 관련된 내용을 변경해야합니까?

답변

4

.dynlib을로드 할 수 있으면 (Programming in Lua, chapter 26) 해당 인터프리터를 변경할 필요가 없습니다. 모듈을 요구하기 전에 .so의 대신 .dynlibs를 찾도록 package.cpath를 변경할 수 있습니다.

0
package.cpath = package.cpath .. ";?.dylib" 
print(package.cpath) 
rtn = require ("libme") 
print(rtn) 

osx에서 올바르게 작동합니다.