lua-users home
lua-l archive

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

1. so/dylib/bundle

.so is used by people who emphasize portability. Apple never uses .so suffix.

.dylib is used for regular dynamic libraries (s.a. liblua.dylib). 

.bundle is used for runtime-loadable dynamic libraries (plugins); these do differ in OS X from dylib's, unlike on some other platforms (Linux, Win32).

Stock Lua LUA_CPATH for OS X only looks for .so suffixes, but the fink distribution allows both .so and .bundle.  For modules brought into fink, I recommend .bundle, but it really does not matter.

2. dyld/dlopen

The dyld/dlopen issue is a separate one, and one where standpoints have changed over time. This explains contradictory statements to be found on the net (check their years!). Current understanding is, OS X Lua is best compiled using LUA_USE_DLOPEN and LUA_USE_POSIX. The LUA_DL_DYLD mode could be eliminated from the codebase. The fink Lua >= Lua 5.1.2-3 uses LUA_USE_DLOPEN.

( I think websites should change color, getting old. Fading colors and crappy corners would show one, it's an old information you're reading.  Too bad they don't.. ;P )

3. gluax

You seem to be using gluax.[ch] for the module making (-DGLUA_LUA51). You don't need -DLUA_USE_MACOSX in this case; it's for building Lua itself.

Here's a sample on how my Lua Lanes builds on OS X:

** Lua 5.1 native module (out/macosx-powerpc/lua51-lanes.bundle): Darwinpowerpc **
cc -I/sw/include  -L/sw/lib -llua -lm   -bundle  -Wall -O2 -o out/macosx-powerpc/lua51-lanes.bundle -DGLUA_LUA51 gluax.c gluax_static.c lanes.c

4. Bundles vs. bundles

This might be your _real_ issue. :)   Apple unfortunately recycles the 'bundle' word for both dynamic library plugins, and "application bundles", which the XCode wizard most likely intends to build. Scrap that, just ignore. This would also explain the "file is not a bundle".  ;)   Since it's an executable application.

I would simply take "Dynamic Library > BSD Dynamic Library" (the simplest) and then make sure "-bundle" is among the compiler flags. In fact, here are the _modified_ parts of a plugin XCode project (Lanes):

SDK path /Developer/SDKs/MacOSX10.4u.sdk
Precompiled headers cache path <empty> 
Header search ../../gluax  /sw/include
Library search /sw/lib
Scan all sources for includes [x]
Mach-O type bundle (means: library bundle, THIS is the important one)
Prebinding [ ]
Bundle loader /sw/bin/lua (the app to use for running your module)
Current library version <empty>
Compatibility version <empty>
Other linker flags -framework Cocoa (if you do any OS X native stuff, in Objective-C)
Perform single object prelink [x]
Prelink libraries <empty>
Product name lua51-lanes (anything goes..) 
Executable prefix <empty> (but still forces 'lib' there....!)
Executable extension bundle
Preprocessor macros GLUA_LUA51 _GNU_SOURCE=1 _THREAD_SAFE

The XCode project notes seems to list some issues worth noting (I've already forgotten them!):

To use this XCode project, set "active build configuration" to Debug.

You may need to add "custom executable" to the "Executables" tree of the project, with:
- path /sw/bin/lua
- custom directory /Users/xxx/.../SDL/
- arguments "test.lua"
- environment LUA_CPATH xcode/build/Debug/lib?.bundle

How to NOT have the "lib" prefix for bundles?   Tried everything, still XCode places it there.  :((

    /usr/bin/g++-4.0 -o /Users/abisoft/Slug/public/2007/SDL/xcode/build/Debug/liblua51-sdl.bundle ...

Have to change the LUA_CPATH instead, so we can debug with this.

AK 25.6.2007 (solved):
After changing dylib->bundle there were some issues, same as:

"Perform single-object prelink" needs to be ticked.

So, in addition I've got a "Lua 5.1" entry under the "Executables" GUI tree (gosh, should really send this project file to you; maybe I will)

Please ask for more details if necessary.


Graham Wakefield kirjoitti 30.10.2007 kello 8:53:

Hi all,

Having a headache trying to build an Xcode project for a lua module. I checked the wiki article, and raided the list archives, and found various contradictory answers.  Would like to know if there is a standard (which can also work as an Xcode project).

I checked existing lua modules, and I can find both .so and .dylib for OSX.
Likewise, I can find dyld and dlopen both recommended for OSX (with dyld being the default, but dlopen being recommended by Apple).

I followed the standard on the wiki [1], using -DGLUA_LUA51 -DLUA_USE_MACOSX for the main application embedding Lua, and using
 -bundle -undefined dynamic_lookup for the module library (being sure to not link against the Lua core).

But a bundle project in Xcode creates a whole folder of stuff, rather than a single binary. No matter what I name the bundle (.so, .dylib, .bundle) I get "file is not a bundle" error.  An OSX bundle is a folder - is Lua not respecting this?  If Lua expects a binary, shouldn't it be a dynamic library rather than a bundle? Sorry if I sound confused - I'm inexperienced at dynamic loading. But I suspect other Lua users on OSX may be too, but wanting to write extension library modules for Lua like me.

Is there actually a standard for building modules on OSX?  Does anyone have an Xcode project that conforms to it (or at least works without hacks) that they would be willing to share?