Skip to content

Instantly share code, notes, and snippets.

@mtolly
Last active March 10, 2024 07:35
Show Gist options
  • Save mtolly/384dbe51f4a78d6d2818 to your computer and use it in GitHub Desktop.
Save mtolly/384dbe51f4a78d6d2818 to your computer and use it in GitHub Desktop.
How to build and install the Mono libgdiplus.dll on a Mac with Homebrew (update: no longer needed, see comments)
#!/bin/bash
# First install XQuartz, then...
brew install freetype fontconfig libpng
ln -s /opt/X11/include/X11 /usr/local/include/X11
git clone [email protected]:mono/libgdiplus
cd libgdiplus
./autogen.sh
make install
@Andotnet
Copy link

Andotnet commented Mar 3, 2020

Just add
runtime.osx.10.10-x64.CoreCompat.System.Drawing
nuget package

@sixhoj
Copy link

sixhoj commented Mar 6, 2020

I can confirm that Andotnet´s solution of installing the nuet package "runtime.osx.10.10-x64.CoreCompat.System.Drawing" solved the issue on MacOs Catalina 10.15.3 (19D76) when running a solution built on .NET Core 3.1.

I had before this installed "libgdiplus" using HomeBrew and also as part of the .NET Mono 6.6.0.166 installation. Doing a find in Terminal I could surmise that the library was installed to the path "/usr/local/lib/libgdiplus.dylib" but my application was unable to locate it.

Specifically the component that was unable to access libgdiplus was Telerik Reporting 14.0.20.219. Before updating this component it was able to find and access libgdiplus.

Thanks a lot Andotnet, you are a life saver!

Best regards,
Hans Sixhöj
A Perfect Day AB

@trofunenko
Copy link

Just add
runtime.osx.10.10-x64.CoreCompat.System.Drawing
nuget package

It is work, thank you sir.

@Wingjam
Copy link

Wingjam commented Mar 17, 2020

Awesome thanks @Andotnet adding runtime.osx.10.10-x64.CoreCompat.System.Drawing dependency solved the issue for MacOs Catalina 10.15.3!

@Houdanny
Copy link

Houdanny commented Apr 8, 2020

Thanks for the help in getting this installed from this thread! Does anyone have any info on how to install libc6-dev on Mac at the moment, because I can't seem to work it out

@Mcafee123
Copy link

Just add
runtime.osx.10.10-x64.CoreCompat.System.Drawing
nuget package

this was it, thx a lot!

@justinormont
Copy link

Just add
runtime.osx.10.10-x64.CoreCompat.System.Drawing
nuget package

This also worked for me. Was needed for the image components in ML.NET.

This NuGet was last published 1.5 years ago, which is concerning from a long-term perspective.
NuGet https://www.nuget.org/packages/runtime.osx.10.10-x64.CoreCompat.System.Drawing/ built from https://github.com/CoreCompat/libgdiplus-packaging.

I did not try the above mentioned brew install mono-libgdiplus, which may also work.

@elahmo
Copy link

elahmo commented Apr 29, 2021

brew install mono-libgdiplus worked for me, the nuget approach didn't on Mojave.

@Oxyrus
Copy link

Oxyrus commented Jan 25, 2022

I ran into this issue, when running a .NET 6.0 App, this is how I solved it

$ brew install mono-libgdiplus
$ sudo ln -s /opt/homebrew/opt/mono-libgdiplus/lib/libgdiplus.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/6.0.0

And that's it

@zaneclaes
Copy link

To get this working with C#/System.Drawing, just do:

sudo ln -s /opt/homebrew/opt/mono-libgdiplus/lib/libgdiplus.dylib /usr/local/lib/

(Which is where the system looks for the library at runtime)

@bw984
Copy link

bw984 commented Sep 13, 2022

These two alone didn't fix the error on my M1 MacBook pro.
$ brew install mono-libgdiplus
$ sudo ln -s /opt/homebrew/opt/mono-libgdiplus/lib/libgdiplus.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/6.0.0

After this third command the program ran without error.
$ sudo ln -s /opt/homebrew/opt/mono-libgdiplus/lib/libgdiplus.dylib /usr/local/lib/

@hariharankanakaraja
Copy link

Solution for M1 Macbook pro

  1. HOMEBREW_NO_AUTO_UPDATE=1 brew reinstall mono-libgdiplus
  2. sudo ln -s /opt/homebrew/opt/mono-libgdiplus/lib/libgdiplus.dylib /usr/local/lib/liblibgdiplus

now works fine.

@WPCJATH
Copy link

WPCJATH commented Feb 26, 2023

Solution for M1 Macbook pro

  1. HOMEBREW_NO_AUTO_UPDATE=1 brew reinstall mono-libgdiplus
  2. sudo ln -s /opt/homebrew/opt/mono-libgdiplus/lib/libgdiplus.dylib /usr/local/lib/liblibgdiplus

now works fine.

@hariharankanakaraja Thanks man! You saved my time. I have trapped here for 2 days since the compatibility of ARM Macs really suck.

@Viper5niper
Copy link

Solution for M1 Macbook pro

  1. HOMEBREW_NO_AUTO_UPDATE=1 brew reinstall mono-libgdiplus
  2. sudo ln -s /opt/homebrew/opt/mono-libgdiplus/lib/libgdiplus.dylib /usr/local/lib/liblibgdiplus

now works fine.

Thanks! You saved me man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment