Rolf Wester
Rolf Wester

Reputation: 217

lua load path for shared objects

I'm using lua 5.3beta under Kubuntu 12.04. I wrapped a c-extension using swig used and gcc4.9 for compiling and linking. If I place my mylib.so in the same directory my lua script is in:

require "mylib"

works fine. But if mylib.so is not within the same directory I get the error message

module 'mylib' not found 

I added the path to mylib to LD_LIBRARY_PATH and inserted

package.path  = package.path .. ';' .. path2mylib .. '/?

in my script. With

package.path  = package.path .. ';' .. path2mylib .. '/?.so

the error message is:

mylib.so:1: unexpected symbol near '<\127>

I guess lua tries to load mylib.so assuming it is a lua-script. It seems that lua looks for shared objects only within certain standard paths including ./ and all paths added to package.path are treated as paths to lua-files.

Is there any way to make lua load my c-extension without placing it into one of the standard library paths?

Upvotes: 4

Views: 1788

Answers (1)

lhf
lhf

Reputation: 72332

The path variable that tells Lua where to find libraries written in C is package.cpath.

package.path is for libraries written in Lua.

Upvotes: 4

Related Questions