lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 4/16/22 13:22, Hugo Musso Gualandi wrote:
Hi list,

I'm trying to improve the Pallene installer and one of the things I
want to do is create a shared library (installable via Luarocks) that
exports low-level C functions. Below I have a minimal example.
The mylib.c exports a C function "mylib_foo". This function is used by
client.c, which implements an extension module that can be "required"
from Lua.

...


gcc -Wall -O2 -fPIC -shared mylib.c -o mylib.so
gcc -Wall -O2 -fPIC -shared client.c -o client.so


You're not linking mylib to client.

Something like (not a daily gcc user, so I could be off here):

  gcc -Wall -O2 -fPIC -shared client.c mylib.so -o client.so


But there's a whole bunch of details to be aware of, especially if you need multi-platform/compiler support.

Instead, you might want to use runtime linking, which Lua itself uses to load modules, but that has it's own complexities. Check loadlib.c in the Lua source.

Scott