lua-users home
lua-l archive

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

On 22/03/2005, at 9:37 PM, Mike Pall wrote:


PA wrote:
Mike Pall provided the following incantation to compile modules on Mac

local CompileCommand = "gcc -O2 -fno-common -c -o"
local LinkCommand = "gcc -bundle -undefined dynamic_lookup -o"

Works like a charm.

Yes, but on Lua 5.1 only!

The original posting asked about Lua 5.0.2. But this one doesn't have any
support for Mac OS X. You need to patch it. Look into src/lib/loadlib.c
at the bottom. However this patch requires you to compile your modules
as dylibs (and not as bundles).

I'm quite happy to go to 5.1 since it offers better OS X support. I'm using Lua under OS X more as a quick test/prototype environ for another platform.

Tried making 5.1 (work5) and this line:

gcc -o lua  lua.o -L. -llua -llualib -lm -ldl -Wl,-E

fails with OS X ld not supporting the '-E' flag. Any hints as to what might work? I'll keep looking at this end, but I'm also learning the ropes with OS X build procedures as well.

Peter Colson wrote:
So far I keep getting a Nil return from loadlib.

The second return value should tell you what went wrong. Try:

lua -e 'print(loadlib("", "_luaopen_xyz"))'

For Lua 5.0.2 "" has to be in the current dir.

Tried this under 5.0.2 and it said 'loadlib not supported'. That makes sense. Then tried it on what I think was an old version of my test dylib using Lua5.1 libs that had been built without the ld '-E' param and it actually got into the luaopen_test (once I added '_' to the func name) before failing with a segmentation fault. Rebuilding my test module and linking to the new Lua5.1 libs produced heaps of undefined symbols which I think is due to removing '-E' and not adding the correct OS X options. Also had to re-ranlib the Lua5.1 libs according to another message that appeared.

With Lua 5.1 you should use require("xyz") and put the module into the
proper path ( /usr/local/lib/lua/5.1/ ).

Under OS X is the extension typically ',dylib' or '.so' or doesn't it really matter?

Peter Colson.