6

I have been using MonoKickstart to get our project - which is built on OpenTK - running on OSX. I got the program to work entirely, but once I removed my Mono.framework (well, actually renamed) the following error popped up:

[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: gdiplus.dll
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Drawing.Bitmap..ctor (System.String filename, Boolean useIcm) [0x00000] in <filename unknown>:0 
  at System.Drawing.Bitmap..ctor (System.String filename) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (string)
 (...)

I have tried adding the "libgdiplus.0.dylib" from my mono installation to the included osx folder (where the mono dynamic libraries also sit) and the executable folder. Creating a dllmap also does not do anything, except for changing the filename in the error message.

I am using the sgen variant, so running in x64 can not be the issue (see also here for a discussion about this).

Tom
  • 532
  • 5
  • 19
  • What version of Mono do you have installed?(3.10 had problems with GDIPlus) and how did you install Mono(recently user had problems with mono installed from brew(also with GDIPlus)...) Use http://www.mono-project.com/download/#download-mac – David Karlaš Mar 08 '15 at 09:40
  • I installed Mono through the original Mono dmg. I think I have 3.12 installed, though I am not sure which version is embedded with MonoKickstart (I see some mentions of mono 2.10.9, but I am pretty sure our game wouldn't run on that at all). I will try and play around a bit with the executables. – Tom Mar 08 '15 at 15:44
  • I have attempted using the boehm version of Mono instead. This however still does not resolve the problem. My suspicion was that the problem was the difference between x64 and x86, but both the fat version and the x86 version of the default kick executable cause the same error. I have tried replacing the libmono-2.0.1.dylib with the one that comes with my mono, but that causes the following error: dyld: Symbol not found: _kCFLocaleCountryCode – Tom Mar 10 '15 at 18:57
  • Which OSX version are you using? – Gusman Apr 15 '15 at 19:42

1 Answers1

2

This error means that mono was unable to locate a library that one of the classes you are trying to use needs.

To preserve compatibility with the .NET Framework, mono uses the same library names as windows. These names are mapped to linux library names using DllMaps.

(Substitute “.so” with “dylib” for MacOS X)

If a library location has not been explicitly specified in a DllMap entry in an application or assembly .config file, Mono will search for a library in a few places:

The directory where the referencing image was loaded from. In any place the system’s dynamic loader is configured to look for shared libraries. For example on Linux this is specified in the $LD_LIBRARY_PATH environment variable and the /etc/ld.so.conf file. On windows the $PATH environment variable is used, instead. The next step in resolving the issue is locating the file on your system.

$ find /usr -name libgdiplus.so /usr/local/lib/libgdiplus.so Aha! There it is. So why can’t mono find it?

By default in basically all distributions of linux the dynamic linker only creates a cache for files in /lib and /usr/lib. Since you have placed your library in /usr/local/lib, it does not know about it. You can verify this using the following command:

ldconfig -p |grep libgdiplus The command should produce no output, because it does not know about the file.

The correct way to fix this problem is to add /usr/local/lib as one of the paths that ldconfig indexes. To do this, add the path to /etc/ld.so.conf and run “ldconfig” as root, which will force the cache to be rebuilt.

The dynamic linker should now know about all the libraries in this path. You can verify this by typing the above command once again:

$ ldconfig -p |grep libgdiplus libgdiplus.so (libc6) => /usr/local/lib/libgdiplus.so Yay! Your application should now run properly.

NOTE: As mentioned above you can also set the $LD_LIBRARY_PATH environment variable to the path containing the library, but this is not as recomended because it can cause other problems and is more difficult to maintain.

For more Information please look at http://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/

Steven Spyrka
  • 678
  • 7
  • 18
  • 1
    `find / -name \*gdiplus\*` yields nothing on OSX Yosemite with mono 4.2.0 installed. Any ideas? – weberc2 Nov 20 '15 at 18:49
  • Looks like I needed to install mono-mdk, but now the requisite library is still not being linked against, and I can't figure out the OSX variant of `ldconfig -p` – weberc2 Nov 20 '15 at 19:07