Reputation: 1013
So a little backstory for what's going on. I'm currently working on building a number of things (including SDL, SDL_image, etc.) and linking it all together in a single executable, and doing it manually. I am making my own custom makefile and only using the command line, not Xcode. (I dislike Xcode) So far I've succeeded in all of this, but I want to start putting Lua scripting on top of my code, so I'm now compiling luajit2.0 and attempting to link that in as well.
However, while SDL worked fine and I could get a window open with a loaded image, luajit refused to link in correctly. It was giving me the dyld: Library not loaded... message, referencing /usr/local/lib even though it not only doesn't exist there, but gcc is given -L on the command line to the folder which holds my built luajit. Using otool -L on my binary gives that directory, even though, again, it doesn't even exist there.
While attempting to google this problem, I came across a solution that gave me this command: install_name_tool -id `pwd`/install/lib/libluajit-5.1.dylib install/lib/libluajit-5.1.dylib
. (from SO) After rebuilding the binary, and using otool on it, I now saw the correct directory for the library. Now, however, while it doesn't give me the dyld error, it gives me a segfault the moment I use a luajit function. (luaL_newstate, specifically)
The command to build my binary is as follows:
gcc -g -Wall -arch x86_64 -framework Cocoa -Iinstall/include -Linstall/lib src/native/main.c -lluajit-5.1.2.0.0 -lSDL2_image -lSDL2 -lSDL2main -lpng -lz -o game
libluajit-5.1.2.0.0.dylib, and all the corresponding symlinks are in install/lib. lua include files are in install/include. What's going wrong here? I'm very confused and would like to just have this start working. I'd rather wrestle code than wrestle gcc and OS X.
EDIT: Per request, the previous error I got before the current "Segmentation fault: 11" error that I'm getting was basically this:
dyld: Library not loaded: /usr/local/lib/luajit-5.1.2.dylib
Referenced from: <my application, forgot this exact bit>
Reason: image not found
And if I did otool -L game I got:
MacBook-Air:old freezerburn$ otool -L game
game:
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
/usr/local/lib/libluajit-5.1.2.dylib (compatibility version 2.0.0, current version 2.0.0)
/Users/freezerburn/Dropbox/Code/lua_engine/old/install/lib/libSDL2_image-1.2.0.dylib (compatibility version 9.0.0, current version 9.5.0)
/Users/freezerburn/Dropbox/Code/lua_engine/old/install/lib/libSDL2-2.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/freezerburn/Dropbox/Code/lua_engine/old/install/lib/libpng15.15.dylib (compatibility version 30.0.0, current version 30.0.0)
/Users/freezerburn/Dropbox/Code/lua_engine/old/install/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.7)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
Even though libluajit was in ./install/lib.
Upvotes: 1
Views: 1464
Reputation: 122381
Why not make life easy for yourself and use Macports:
$ xcode-select -switch /Applications/Xcode.app/Contents/Developer
$ sudo port selfupdate
$ sudo port install libsdl_image luajit
This will install the ports you request and any dependencies.
You can then concentrate on your project with the knowledge that a qualified team is looking after all that other stuff.
Upvotes: 0
Reputation: 1515
The shared library has an install path. This means you must build and install with the proper PREFIX, see the install docs. Or consider linking with the static LuaJIT library -- loading dynamic libraries from non-system locations is a can of worms.
The segfault is due to not following the LuaJIT embedding instructions for OSX/x64.
Upvotes: 6