How to setup SDL with C# bindings in Visual Studio for Mac?

Hello,

I’m not sure if this is the right place to ask, but I’ll try anyway. I would like to use SDL on Mac with the SDL2C# wrapper, but I’m having trouble with getting things up and running. What I have so far:

  • .dylibs for SDL2, SDL2_image, SDL2_mixer and SDL2_ttf
  • A Visual Studio solution with:
    – A project for all the SDL2C# files.
    – A (console) project for the game code.

Everything builds just fine, but when I try to call an SDL function I get a DllNotFoundException ("Unable to load DLL ‘SDL2.dll’: The specified module or one of its dependencies could not be found.). I tried adding the .dylibs to the wrapper project and setting them to “copy to output directory”, but the error persists. I also verified that the names of the .dylibs match the ones specified in the dllmaps found in SDL2-CS.dll.config.

I don’t know what the problem is and I haven’t been able to find any documentation or tutorials on how to do this. Are the .dylibs in the wrong location, am I missing some dependencies, did I overlook something else…? Any help would be greatly appreciated.

Nevermind, I finally figured out the issue. I’m using .NET Core 2.0 and dllmap is a Mono function, so the mapping between native libraries on different platforms is not working. Therefore, the game was still looking for a .dll file instead of a .dylib. There is a simple workaround to resolve this until Microsoft adds this functionality to .NET Core:

  1. Remove the .dll extension of the “nativeLibName” variable in each wrapper file. E.g. in SDL2.cs the value of nativeLibName is changed from “SDL2.dll” to just “SDL2”. This doesn’t cause any problems because it is actually not necessary to specify the extension.
  2. Change the default name of each native library to the value of the corresponding nativeLibName. E.g. on Mac libSDL2-2.0.0.dylib has to be changed to simply SDL2.dylib.
  3. Everything should now work!

More info: https://github.com/FNA-XNA/FNA/issues/145