Question

I'm trying to use the SDL2 C# bindings (SDL2-CS), but for some reason, the Mac version of Mono isn't finding the library. libSDL2-2.0.0.dylib is installed in /usr/local/lib/ and I've added it to $DYLD_LIBRARY_PATH, but I'm still getting a System.DLLNotFoundException. How can I get this to work?

Was it helpful?

Solution

On OS X, Mono is typically 32-bit, and installing through either MacPorts or a source build will yield a 64-bit binary. This could very well be the source of the problem, and you can check by setting export MONO_LOG_LEVEL=debug. If you see something along the lines of this:

Mono: DllImport error loading library 'dlopen(/usr/local/lib/libSdl-2.0.0.dylib, 9): no suitable image found.
Did find: /opt/local/lib/libSdl-2.0.0.dylib: mach-o, but wrong architecture'.

then this is your problem right here. Compile SDL2 from source in 32-bit mode like so:

$ export CFLAGS="-arch i386"
$ export LDFLAGS="-arch i386"
$ ./configure
$ make

and to just to make sure that it's right, run:

$ file build/.libs/libSDL2-2.0.0.dylib

which should result in:

$ build/.libs/libSDL2-2.0.0.dylib: Mach-O dynamically linked shared library i386

Now just make install, and you should be good to go!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top