I have been struggling to get my sprite font loaded for the past few days. I am using an M1 macOS laptop. I had already installed the c++ distributions for x64 that were recommended for the freeimage library to work. And, I had already gotten images to appear in game.
When I ran dotnet tool run mgcb Content.mgcb
from in my project I was getting this error.
error: Processor 'FontDescriptionProcessor' had unexpected failure!
System.DllNotFoundException: Unable to load shared library 'freetype6' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libfreetype6, 0x0001): tried: 'libfreetype6' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibfreetype6' (no such file), '/usr/lib/libfreetype6' (no such file, not in dyld cache), 'libfreetype6' (no such file), '/usr/local/lib/libfreetype6' (no such file), '/usr/lib/libfreetype6' (no such file, not in dyld cache)
at SharpFont.FT.FT_Init_FreeType(IntPtr& alibrary)
at SharpFont.Library..ctor()
at Microsoft.Xna.Framework.Content.Pipeline.Graphics.SharpFontImporter.Import(FontDescription options, String fontName) in /home/runner/work/MonoGame/MonoGame/MonoGame.Framework.Content.Pipeline/Graphics/Font/SharpFontImporter.cs:line 29
at Microsoft.Xna.Framework.Content.Pipeline.Processors.FontDescriptionProcessor.ImportFont(FontDescription options, Single& lineSpacing, Int32& yOffsetMin, ContentProcessorContext context, String fontName) in /home/runner/work/MonoGame/MonoGame/MonoGame.Framework.Content.Pipeline/Processors/FontDescriptionProcessor.cs:line 194
at Microsoft.Xna.Framework.Content.Pipeline.Processors.FontDescriptionProcessor.Process(FontDescription input, ContentProcessorContext context) in /home/runner/work/MonoGame/MonoGame/MonoGame.Framework.Content.Pipeline/Processors/FontDescriptionProcessor.cs:line 80
at Microsoft.Xna.Framework.Content.Pipeline.ContentProcessor`2.Microsoft.Xna.Framework.Content.Pipeline.IContentProcessor.Process(Object input, ContentProcessorContext context) in /home/runner/work/MonoGame/MonoGame/MonoGame.Framework.Content.Pipeline/ContentProcessor.cs:line 60
at MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.ProcessContent(PipelineBuildEvent pipelineEvent) in /home/runner/work/MonoGame/MonoGame/MonoGame.Framework.Content.Pipeline/Builder/PipelineManager.cs:line 717
I used brew info freetype
to find where that the freetype library was installed to /opt/homebrew/Cellar/freetype/2.13.2/lib/libfreetype.6.dylib
.
To solve the error above, I created a symlink from the homebrew library path to where monogame was actually looking: /usr/local/lib/libfreetype6.dylib
.
The command I ran was ln -s /opt/homebrew/Cellar/freetype/2.13.2/libfreetype.6.dylib /usr/local/lib/libfreetype6.dylib/
.
Note: libfreetype.6.dylib
became libfreetype6.dylib
!
Note: If you get ln: /usr/local/lib/libfreetype.6.dylib: Permission denied
, like I did, try running the same ln
command with sudo
before.
When running dotnet tool run mgcb Content.mgcb
now, everything works and when I run my project I see the font displaying!