Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Has anyone had any luck getting SFML.NET on .NET Core running on MacOS?  (Read 11716 times)

0 Members and 1 Guest are viewing this topic.

ashley

  • Newbie
  • *
  • Posts: 6
    • View Profile
I was pretty excited about the migration to .NET Core (/standard?), and now I can build on any OS perfectly, which is fantastic as I can run CI on Linux now, but as soon as I try to actually run anything linking to SFML, the runtime linking fails on MacOS and Linux. This is true of examples, my own project, and a test project I set up to try to diagnose with a minimal example.

Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'libcsfml-graphics.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibcsfml-graphics.dylib.dylib, 1): image not found

One thing I found curious is that "dlopen(liblibcsfml-graphics.dylib.dylib)" call. It seems to me that the DllImport is prepending lib and appending .dylib of its own accord, so I tried removing the "lib" and ".dylib" from the const string in SFML.NET and rebuilding. This results in "dlopen(csfml-graphics)" which I find strange -- the appending seems to be conditional on it already being of the correct form.

I'm not sure if this is normal, but it seems very strange to me. In any case, I tried putting copies of the dylib file with all sorts of names - "csfml-graphics", "libcsfml-graphics.dylib" and "liblibcsfml-graphics.dylib.dylib" for good measure. It doesn't seem to find any of these, even though it correctly finds the corresponding DLLs on Windows in the same directory (I have these libraries in the execution directory in project-path/bin/.../).

I've spent quite a lot of time digging and playing around, but I'm not really getting anywhere, so I was wondering if anyone else has invested some time into running new builds on SFML.NET on MacOS without Mono? If so, I'd appreciate some pointers on how to get it working at runtime!

If no-one has gotten it working, but someone has some time and fancies helping, I'm happy to provide more information and a sample project.

Thanks in advance for any help and pointers!

rustybox

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Has anyone had any luck getting SFML.NET on .NET Core running on MacOS?
« Reply #1 on: January 06, 2019, 03:43:26 pm »
Yes it works fine in dev if I set DYLD_PRINT_LIBRARIES and DYLD_PRINT_FRAMEWORKS.

When you release you will be creating an app package with an osx/ folder into which you can put your dependencies.

Just set the environment variables for now.

ashley

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Has anyone had any luck getting SFML.NET on .NET Core running on MacOS?
« Reply #2 on: January 07, 2019, 07:02:24 pm »
Thanks for the reply!

Setting these environment variables just gets me a more verbose version of the same error, terminating in:

dyld: loaded: /Users/ashley/RiderProjects/SFML.NET Test/SFML.NET Test/bin/Debug/netcoreapp2.2/libcsfml-window.dylib
dyld: unloaded: /Users/ashley/RiderProjects/SFML.NET Test/SFML.NET Test/bin/Debug/netcoreapp2.2/libcsfml-window.dylib
dyld: loaded: libcsfml-window.dylib
dyld: unloaded: libcsfml-window.dylib

Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'libcsfml-window.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibcsfml-window.dylib.dylib, 1): image not found
   at SFML.Window.VideoMode.sfVideoMode_getDesktopMode()
   at SFML.Window.VideoMode.get_DesktopMode() in /Users/ashley/SFML.Net/src/Window/VideoMode.cs:line 86
   at SFML.NET_Test.Program.Main(String[] args) in /Users/ashley/RiderProjects/SFML.NET Test/SFML.NET Test/Program.cs:line 12


I wonder if one of my libraries is at the wrong version -- are you using builds of CSFML 2.5? I've tried 2.1, 2.2 and 2.5 and all of them seem to result in this issue for me.

Additionally, I don't have any other libraries in that folder outside of the SFML ones; are you including any openal dylibs or anything?

ashley

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Has anyone had any luck getting SFML.NET on .NET Core running on MacOS?
« Reply #3 on: September 16, 2019, 01:04:04 am »
Necro, but it seems in retrospect I was just using the wrong Nuget packages.

The correct ones are currently SFML.{Net/System/...}/2.5.0.

For others in the same situation later, check the date of release of the Nuget packages and make sure you're not using years old ones!
« Last Edit: September 16, 2019, 01:09:54 am by ashley »

drmelon

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Has anyone had any luck getting SFML.NET on .NET Core running on MacOS?
« Reply #4 on: February 21, 2020, 01:40:36 pm »
I came across this thread when googling feverishly, unable to get SFML.Net to run on MacOS after building with dotnet.
I managed to get it to work by doing the following;
1. Build your application with dotnet publish.
2. In the resulting folder with the executable binary, create a new hierarchy of directories like so: runtimes/osx/native
3. Download CSFML's Mac version from the SFML site: https://www.sfml-dev.org/download/csfml/
4. Put the *.dylib files from the lib folder of CSFML in the runtimes/osx/native folder.
5. Download SFML's Mac version from the SFML site: https://www.sfml-dev.org/download/sfml/2.5.1/
6. Copy the Frameworks folder to the same folder as your program binary, so it sits next to the runtimes folder.
7. Copy the contents of the extlibs folder to that new Frameworks folder.
8. Open a terminal window in the same directory as your program binary and write:
install_name_tool -add_rpath @executable_path/Frameworks YourProgramNameHere

And that should do it! I did a lot of mucking around with the otool -l tool to find out where it was trying to load the CSFML/SFML bindings from. This should also give you what you need to fully publish your Mac build in a .App folder/container.

It seems that the CSFML .nuget package doesn't contain anything for Mac at the moment, also. That might need fixing sometime!