TextureImporter error - Mac OS Monterey 12.6

Hey all,

I’ve been trying to get my dev environment set up on my Mac per the instructions listed on the official MonoGame site and I have been having some issues.

I was able to eventually get Visual Studio 2022 to run a MonoGame project (target: mgdesktopgl) created with the .NET 6 SDK listed at the end of the article. The game runs great! However, the moment I had an image to my Content.mgcb file via the MGCB editor, my game won’t compile and I get the following error:

“Importer “TextureImporter” had unexpected failure!”
“The command “dotnet mgcb /quiet /@:”[filepath]/MyProject/Content/Content.mgcb” /platform:DesktopGL /outputDir:"[filepath]/MyProject/Content/bin/DesktopGL/Content" /intermediateDir:"[filepath]MyProject/Content/obj/DesktopGL/net6.0/Content" /workingDir:"[filepath]/MyProject/Content/"" exited with code 1. (MSB3073) (MyProject)"

Could I please get some advice here? I’ve seen elsewhere people recommend downloading VS 2012 as there is some sort of arcane dependency only that version actually has but I am on Mac so that is not possible afaik.

Thank you so much for any help, I just want to do a very simple task and it has been quite the headache.

Hi,
check that you have version 3.8.1.303
try running mgcb-editor-mac from command line dotnet mgcb-editor-mac
tell me if your mgcb-editor starts correctly?

If I run mgcb-editor-mac I get

zsh: command not found: mgcb-editor-mac

If I run mgcb-editor I get

Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET program, but dotnet-mgcb-editor-mac does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

I have installed mgcb editor as instructed in all Mac tutorials I could find but it doesn’t seem to work. I have both .NET 6.0 x64 and ARM64 installed, not sure if that is relevant.

Specifically I cannot run

mgcb-editor --register

as this throws the same “could not execute error”

After following Stuggling Doge’s tutorial for M1 Macs, I get a more complete build error that could help as well:

Building DesktopGLTest (Debug)
Build started 09/21/2022 12:09:39.
__________________________________________________
Project "/Users/gacarr/Documents/game-dev/DesktopGLTest/DesktopGLTest.csproj" (Build target(s)):

Target RunContentBuilder:
    dotnet tool restore
    Tool 'dotnet-mgcb' (version '3.8.1.303') was restored. Available commands: mgcb
    Tool 'dotnet-mgcb-editor' (version '3.8.1.303') was restored. Available commands: mgcb-editor
    Tool 'dotnet-mgcb-editor-linux' (version '3.8.1.303') was restored. Available commands: mgcb-editor-linux
    Tool 'dotnet-mgcb-editor-windows' (version '3.8.1.303') was restored. Available commands: mgcb-editor-windows
    Tool 'dotnet-mgcb-editor-mac' (version '3.8.1.303') was restored. Available commands: mgcb-editor-mac
    
    Restore was successful.
    dotnet mgcb /quiet /@:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/Content.mgcb" /platform:DesktopGL /outputDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/bin/DesktopGL/Content" /intermediateDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/obj/DesktopGL/net6.0/Content" /workingDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/"
    /Users/gacarr/Documents/game-dev/DesktopGLTest/Content/ball.png
    /Users/gacarr/Documents/game-dev/DesktopGLTest/Content/ball.png : error : Importer 'TextureImporter' had unexpected failure!
    System.DllNotFoundException: Unable to load shared library 'FreeImage' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libFreeImage, 0x0001): tried: 'libFreeImage' (no such file), '/usr/local/lib/libFreeImage' (no such file), '/usr/lib/libFreeImage' (no such file), '/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/libFreeImage' (no such file)
       at FreeImageAPI.FreeImage.GetFileTypeS(String filename, Int32 size)
       at FreeImageAPI.FreeImage.GetFileType(String filename, Int32 size) in /home/runner/work/MonoGame/MonoGame/MonoGame.Framework.Content.Pipeline/Utilities/FreeImageAPI.cs:line 122
       at Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.Import(String filename, ContentImporterContext context) in /home/runner/work/MonoGame/MonoGame/MonoGame.Framework.Content.Pipeline/TextureImporter.cs:line 83
       at Microsoft.Xna.Framework.Content.Pipeline.ContentImporter`1.Microsoft.Xna.Framework.Content.Pipeline.IContentImporter.Import(String filename, ContentImporterContext context) in /home/runner/work/MonoGame/MonoGame/MonoGame.Framework.Content.Pipeline/ContentImporter.cs:line 45
       at MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.ProcessContent(PipelineBuildEvent pipelineEvent) in /home/runner/work/MonoGame/MonoGame/MonoGame.Framework.Content.Pipeline/Builder/PipelineManager.cs:line 669
    /Users/gacarr/.nuget/packages/monogame.content.builder.task/3.8.1.303/build/MonoGame.Content.Builder.Task.targets(142,5): error MSB3073: The command "dotnet mgcb /quiet /@:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/Content.mgcb" /platform:DesktopGL /outputDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/bin/DesktopGL/Content" /intermediateDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/obj/DesktopGL/net6.0/Content" /workingDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/"" exited with code 1.
Done building target "RunContentBuilder" in project "DesktopGLTest.csproj" -- FAILED.

Done building project "DesktopGLTest.csproj" -- FAILED.

Build FAILED.

/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/ball.png : error : Importer 'TextureImporter' had unexpected failure!
/Users/gacarr/.nuget/packages/monogame.content.builder.task/3.8.1.303/build/MonoGame.Content.Builder.Task.targets(142,5): error MSB3073: The command "dotnet mgcb /quiet /@:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/Content.mgcb" /platform:DesktopGL /outputDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/bin/DesktopGL/Content" /intermediateDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/obj/DesktopGL/net6.0/Content" /workingDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/"" exited with code 1.
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:00.46

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Build: 2 errors, 0 warnings

It definitely seems the issue is mgcb? So I guess I should rephrase my question to “how can I properly install mgcb-editor” on an M1 Mac?

Okay so running

mgcb-editor

from within my project folder seems to work now? It opens up the mgcb gui. But I still get the same build error when I try to run my project.

ok you have the m1 chip

Hi there! It should be an easy fix… What your going to want to do is follow the steps you did to install SDL in my tutorial, but instead your gonna want to clone FreeImage, just simply google something like ‘FreeImage GitHub’. Clone it, run the makefile, and run sudo make install. Should fix it!

Edit: Just saw your other post below! Do the same thing for freetype, clone it, cd into the directory, run make and then sudo make install.

Tried adding a spritefont to see if it was just a problem with pngs and I got the following error when I tried to build:


Building DesktopGLTest (Debug)
Build started 09/21/2022 13:46:10.
__________________________________________________
Project "/Users/gacarr/Documents/game-dev/DesktopGLTest/DesktopGLTest.csproj" (Build target(s)):

Target RunContentBuilder:
    dotnet tool restore
    Tool 'dotnet-mgcb' (version '3.8.1.303') was restored. Available commands: mgcb
    Tool 'dotnet-mgcb-editor' (version '3.8.1.303') was restored. Available commands: mgcb-editor
    Tool 'dotnet-mgcb-editor-linux' (version '3.8.1.303') was restored. Available commands: mgcb-editor-linux
    Tool 'dotnet-mgcb-editor-windows' (version '3.8.1.303') was restored. Available commands: mgcb-editor-windows
    Tool 'dotnet-mgcb-editor-mac' (version '3.8.1.303') was restored. Available commands: mgcb-editor-mac
    
    Restore was successful.
    dotnet mgcb /quiet /@:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/Content.mgcb" /platform:DesktopGL /outputDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/bin/DesktopGL/Content" /intermediateDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/obj/DesktopGL/net6.0/Content" /workingDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/"
    /Users/gacarr/Documents/game-dev/DesktopGLTest/Content/Score.spritefont
    	Building Font /System/Library/Fonts/Supplemental/Arial.ttf
    /Users/gacarr/Documents/game-dev/DesktopGLTest/Content/Score.spritefont : 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), '/usr/local/lib/libfreetype6' (no such file), '/usr/lib/libfreetype6' (no such file), '/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/libfreetype6' (no such file)
       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
    /Users/gacarr/.nuget/packages/monogame.content.builder.task/3.8.1.303/build/MonoGame.Content.Builder.Task.targets(142,5): error MSB3073: The command "dotnet mgcb /quiet /@:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/Content.mgcb" /platform:DesktopGL /outputDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/bin/DesktopGL/Content" /intermediateDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/obj/DesktopGL/net6.0/Content" /workingDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/"" exited with code 1.
Done building target "RunContentBuilder" in project "DesktopGLTest.csproj" -- FAILED.

Done building project "DesktopGLTest.csproj" -- FAILED.

Build FAILED.

/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/Score.spritefont : error : Processor 'FontDescriptionProcessor' had unexpected failure!
/Users/gacarr/.nuget/packages/monogame.content.builder.task/3.8.1.303/build/MonoGame.Content.Builder.Task.targets(142,5): error MSB3073: The command "dotnet mgcb /quiet /@:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/Content.mgcb" /platform:DesktopGL /outputDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/bin/DesktopGL/Content" /intermediateDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/obj/DesktopGL/net6.0/Content" /workingDir:"/Users/gacarr/Documents/game-dev/DesktopGLTest/Content/"" exited with code 1.
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:00.59

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Build: 2 errors, 0 warnings

Is this an issue with my MonoGame installation? Am I missing a dependency? I am confused why such basic functions would be broken.

Here is an image of my sln. Is it missing something important?

Here is the project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <RollForward>Major</RollForward>
    <PublishReadyToRun>false</PublishReadyToRun>
    <TieredCompilation>false</TieredCompilation>
  </PropertyGroup>
  <PropertyGroup>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <ApplicationIcon>Icon.ico</ApplicationIcon>
  </PropertyGroup>
  <ItemGroup>
    <None Remove="Icon.ico" />
    <None Remove="Icon.bmp" />
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Include="Icon.ico" />
    <EmbeddedResource Include="Icon.bmp" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
    <PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" />
  </ItemGroup>
  <Target Name="RestoreDotnetTools" BeforeTargets="Restore">
    <Message Text="Restoring dotnet tools" Importance="High" />
    <Exec Command="dotnet tool restore" />
  </Target>
</Project>

Thank you! Unfortunately, I can’t seem to get any of the FreeImage installations to build. It seems they require an SDK for PPC and i386 but I can’t find either of those online. The repo I am pulling from can be found here.

When I run make I get this output:

/Library/Developer/CommandLineTools/usr/bin/make -f Makefile.osx 
/Library/Developer/CommandLineTools/usr/bin/clang++ -Wno-ctor-dtor-privacy -D__ANSI__ -std=c++11 -stdlib=libc++ -Wc++11-narrowing -Os -fexceptions -fvisibility=hidden -DNO_LCMS -D__ANSI__ -arch x86_64 -I. -ISource -ISource/Metadata -ISource/FreeImageToolkit -ISource/LibJPEG -ISource/LibPNG -ISource/LibTIFF4 -ISource/ZLib -ISource/LibOpenJPEG -ISource/LibWebP -ISource/LibJXR -ISource/LibJXR/common/include -ISource/LibJXR/image/sys -ISource/LibJXR/jxrgluelib  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.11 -c Source/FreeImage/PluginTIFF.cpp -o Source/FreeImage/PluginTIFF.o-x86_64
Source/FreeImage/PluginTIFF.cpp:135:8: error: use of undeclared identifier 'half'
 const half::uif half::_toFloat[1 << 16] =
       ^
Source/FreeImage/PluginTIFF.cpp:135:18: error: use of undeclared identifier 'half'
 const half::uif half::_toFloat[1 << 16] =
                 ^
Source/FreeImage/PluginTIFF.cpp:137:23: error: use of undeclared identifier 'half'
 const unsigned short half::_eLut[1 << 9] =
                      ^
Source/FreeImage/PluginTIFF.cpp:514:2: warning: 'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases [-Wauto-storage-class]
        auto int e = (x.i >> 23) & 0x000001ff;
        ^~~~~
Source/FreeImage/PluginTIFF.cpp:525:6: warning: 'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases [-Wauto-storage-class]
            auto int m = x.i & 0x007fffff;
            ^~~~~
Source/FreeImage/PluginTIFF.cpp:1386:9: warning: enumeration value 'FIT_UNKNOWN' not handled in switch [-Wswitch]
        switch(fit) {
               ^~~
Source/FreeImage/PluginTIFF.cpp:1386:9: note: add missing switch cases
        switch(fit) {
               ^
3 warnings and 3 errors generated.
make[1]: *** [Source/FreeImage/PluginTIFF.o-x86_64] Error 1
make: *** [default] Error 2

And when I try to run make for FreeType (from gitlab) I get this error:


FreeType build system -- automatic system detection

The following settings are used:

  platform                    unix
  compiler                    cc
  configuration directory     ./builds/unix
  configuration rules         ./builds/unix/unix.mk

If this does not correspond to your system or settings please remove the file
`config.mk' from this directory then read the INSTALL file for help.

Otherwise, simply type `/Library/Developer/CommandLineTools/usr/bin/make' again to build the library,
or `/Library/Developer/CommandLineTools/usr/bin/make refdoc' to build the API reference (this needs Python >= 3.5).

Checking out submodule in `subprojects/dlg'
git submodule init
Submodule 'dlg' (https://github.com/nyorain/dlg.git) registered for path 'subprojects/dlg'
git submodule update
Cloning into '/Users/gacarr/repos/freetype/subprojects/dlg'...
Submodule path 'subprojects/dlg': checked out 'd142e646e263c89f93663e027c2f0d03739ab42d'
Copying files from `subprojects/dlg' to `src/dlg' and `include/dlg'
mkdir include/dlg
cp subprojects/dlg/include/dlg/output.h include/dlg
cp subprojects/dlg/include/dlg/dlg.h include/dlg
cp subprojects/dlg/src/dlg/dlg.c src/dlg
Generating modules list in ./objs/ftmodule.h...
done.
* module: truetype  (Windows/Mac font files with extension *.ttf or *.ttc)
* module: type1     (Postscript font files with extension *.pfa or *.pfb)
* module: cff       (OpenType fonts with extension *.otf)
* module: cid       (Postscript CID-keyed fonts, no known extension)
* module: pfr       (PFR/TrueDoc font files with extension *.pfr)
* module: type42    (Type 42 font files with no known extension)
* module: winfnt    (Windows bitmap fonts with extension *.fnt or *.fon)
* module: pcf       (pcf bitmap fonts)
* module: bdf       (bdf bitmap fonts)
* module: sfnt      (helper module for TrueType & OpenType formats)
* module: autofit   (automatic hinting module)
* module: pshinter  (Postscript hinter module)
* module: smooth    (anti-aliased bitmap renderer)
* module: raster    (monochrome bitmap renderer)
* module: ot-svg    (OT-SVG glyph renderer module)
* module: sdf       (signed distance field renderer)
* module: bsdf      (bitmap to signed distance field converter)
* module: psaux     (Postscript Type 1 & Type 2 helper module)
* module: psnames   (Postscript & Unicode Glyph name handling)
cd builds/unix; \
	        ./configure 
/bin/sh: ./configure: No such file or directory
make: *** [setup] Error 127

Feel like I’m missing something fundamental since nothing seems to work? Any help is appreciated.

Eek, sorry! Totally forgot that FreeImage needs to be modified a bit to build properly ;p. So, there are a few steps you need to do, first off edit the follow files:

Add at top of segdec.c:

#ifdef __APPLE__
    #include <libkern/OSByteOrder.h>
    #define _byteswap_ulong(x) _OSSwapInt32
#endif

Add at top of gzguts.h:

#ifdef __APPLE__
    #include <unistd.h>
#endif

Add at line 18 of gzlib.c:

#ifdef __APPLE__
    #define _LARGEFILE64_SOURCE     /* See feature_test_macros(7) */
    #include <sys/types.h>
    #include <unistd.h>
#endif

Add at top of both copies of JXRGlueJxr.c (might only be one):

#ifdef __APPLE__
    #include <wchar.h>
#endif

Then, open Makefile.osx in a text editor and change it to this:

# -*- Makefile -*-
# Mac OSX makefile for FreeImage

# This file can be generated by ./gensrclist.sh
include Makefile.srcs

# Find SDK path via xcode-select, backwards compatible with Xcode vers < 4.5
MACOSX_SYSROOT = $(shell xcrun --show-sdk-path)
# Specify deployement target here
MACOSX_DEPLOYMENT_TARGET = 10.11

# General configuration variables:
CC_I386 = $(shell xcrun -find clang)
CC_X86_64 = $(shell xcrun -find clang)
CPP_I386 = $(shell xcrun -find clang++)
CPP_X86_64 = $(shell xcrun -find clang++)
MACOSX_DEPLOY = -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET)
COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS -D__ANSI__ -DDISABLE_PERF_MEASUREMENT -DPNG_ARM_NEON_OPT=0
COMPILERFLAGS_I386 = -arch i386
COMPILERFLAGS_X86_64 = -arch x86_64 -arch arm64
COMPILERPPFLAGS = -Wno-ctor-dtor-privacy -D__ANSI__ -std=c++11 -stdlib=libc++ -Wc++11-narrowing
INCLUDE +=
INCLUDE_I386 = -isysroot $(MACOSX_SYSROOT)
INCLUDE_X86_64 = -isysroot $(MACOSX_SYSROOT)
CFLAGS_I386 = $(COMPILERFLAGS) $(COMPILERFLAGS_I386) $(INCLUDE) $(INCLUDE_I386) $(MACOSX_DEPLOY)
CFLAGS_X86_64 = $(COMPILERFLAGS) $(COMPILERFLAGS_X86_64) $(INCLUDE) $(INCLUDE_X86_64) $(MACOSX_DEPLOY)
CPPFLAGS_I386 = $(COMPILERPPFLAGS) $(CFLAGS_I386)
CPPFLAGS_X86_64 = $(COMPILERPPFLAGS) $(CFLAGS_X86_64)
LIBRARIES_I386 = $(MACOSX_DEPLOY) -Wl,-syslibroot $(MACOSX_SYSROOT)
LIBRARIES_X86_64 = $(MACOSX_DEPLOY) -Wl,-syslibroot $(MACOSX_SYSROOT)
LIBTOOL = libtool
LIPO = lipo

TARGET = freeimage
STATICLIB = lib$(TARGET).a
SHAREDLIB = lib$(TARGET).$(VER_MAJOR).$(VER_MINOR).dylib
VERLIBNAME = lib$(TARGET).$(VER_MAJOR).dylib
LIBNAME = lib$(TARGET).dylib
HEADER = Source/FreeImage.h

.SUFFIXES: .o-i386 .o-x86_64
MODULES_I386 = $(SRCS:.c=.o-i386)
MODULES_X86_64 = $(SRCS:.c=.o-x86_64)
MODULES_I386 := $(MODULES_I386:.cpp=.o-i386)
MODULES_X86_64 := $(MODULES_X86_64:.cpp=.o-x86_64)

DESTDIR ?= /usr/local
INSTALLDIR ?= $(DESTDIR)/lib
INCDIR ?= $(DESTDIR)/include

default: all

all: dist

# ONLY STATIC AND DYNAMIC 64 BIT // START ---

dist: FreeImage
	cp *.a Dist
	cp *.dylib Dist
	cp Source/FreeImage.h Dist

$(STATICLIB): $(STATICLIB)-x86_64
	cp -p $(STATICLIB)-x86_64 $(STATICLIB)

# --- END

# STATIC AND DYNAMIC 32 and 64 BIT // START ---

#dist: FreeImage
#	cp *.a Dist
#	cp *.dylib Dist
#	cp Source/FreeImage.h Dist

FreeImage: $(STATICLIB) $(SHAREDLIB)

#$(STATICLIB): $(STATICLIB)-i386 $(STATICLIB)-x86_64
#	$(LIPO) -create $(STATICLIB)-i386 $(STATICLIB)-x86_64 -output $(STATICLIB)

# --- END

$(STATICLIB)-i386: $(MODULES_I386)
	$(LIBTOOL) -arch_only i386 -o $@ $(MODULES_I386)

$(STATICLIB)-x86_64: $(MODULES_X86_64)
	$(LIBTOOL) -o $@ $(MODULES_X86_64)

$(SHAREDLIB): $(SHAREDLIB)-x86_64
	$(LIPO) -create $(SHAREDLIB)-x86_64 -output $(SHAREDLIB)

$(SHAREDLIB)-i386: $(MODULES_I386)
	$(CPP_I386) -arch i386 -dynamiclib $(LIBRARIES_I386) -o $@ $(MODULES_I386)

$(SHAREDLIB)-x86_64: $(MODULES_X86_64)
	$(CPP_X86_64) -dynamiclib $(LIBRARIES_X86_64) -o $@ $(MODULES_X86_64)

.c.o-i386:
	$(CC_I386) $(CFLAGS_I386) -c $< -o $@

.c.o-x86_64:
	$(CC_X86_64) $(CFLAGS_X86_64) -c $< -o $@

.cpp.o-i386:
	$(CPP_I386) $(CPPFLAGS_I386) -c $< -o $@

.cpp.o-x86_64:
	$(CPP_X86_64) $(CPPFLAGS_X86_64) -c $< -o $@

install:
	install -d -m 755 -o $(USER) -g staff $(INCDIR) $(INSTALLDIR)
	install -m 644 -o $(USER) -g staff $(HEADER) $(INCDIR)
	install -m 644 -o $(USER) -g staff $(SHAREDLIB) $(STATICLIB) $(INSTALLDIR)
	ranlib -sf $(INSTALLDIR)/$(STATICLIB)
	ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(VERLIBNAME)
	ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(LIBNAME)

clean:
	rm -f core Dist/*.* u2dtmp* $(MODULES_I386) $(MODULES_X86_64) $(STATICLIB) $(STATICLIB)-i386 $(SHAREDLIB) $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64

Once this has all been done, try to install it once again, should work this time hopefully :O!

As a quick fix to get Monogame working on M1 do the following:

Install both the arm64 and the x64 SDKs of Dotnet SDK 6!
The arm64 version of the SDK is already installed with VS2022.

In Visual Studio 2022 in Preferences (Visual Studio->Preferences) under
SDK Locations → .Net Core change the path of the .NET Core Command Line to:
/usr/local/share/dotnet/x64/dotnet
Restart VS2022

After that you should be able to build your MonoGame project with an Apple M1.

As a side note: Installing the x64 SDK of dotnet 6 is enough to be able to run the MonoGame Content Builder Editor (using dotnet mgdb-editor inside your project), but you have to set the runtime which your game is built against explicitly to x64.
After that your are able to build, run and debug your game. Unfortunately only by using the x64 runtime instead of arm64. But once MonoGame runs fully (including building) on arm64 this is the way to go.
This should be added to the docs as new users might get confused with the proper setup on mac.

WOW that fixed it! Thank you so much! I was getting worried I had messed something up but that was an easy fix.

If someone could add this to the docs for Mac setup I bet this would help a lot of people; let me know if it’s something I could help with. I saw a handful of others online having issues with M1s but not a lot of answers.

And thank you Struggling Doge for your patient answers and awesome write-up on M1 as well, you provided one of the only resources I could find online about this stuff. Much love and hope you all have a nice rest of your day!

1 Like

It took me a while to find this out. Even installing FreeImage via Homebrew brew install freeimage didn’t work at all.
I haven’t tested this with Visual Studio Code yet. I will post an update once I figured it out as well because it might be interesting.

@mrhlemut This might be helpful for others, so it should be added to the docs. See my post.

Yeah, the documentation is lacking to indicate how to change which SDK is used to workaround this issue.

I don’t think it is possible to bypass the version of freeimage used by MGCB by installing it system-wide manually.

The real fix would be to build freeimage with arm64+x64 binary and patch monogame itself so that MGCB can build stuff on M1/M2 natively. It’s not just freeimage, there’s a bunch of dependencies to rebuild and some of them aren’t open-source and don’t provide arm64 binaries.

What type of file is your texture? I use Monogame on an M-1 Mac without issues fir the last 2 years. However, I’m using Visual Studio 2019.

Can you check which sdk is being used? If it’s the arm64 or x64 version? Despite VS2019 being x64 only I’m sure it is using the x64 dotnet sdk by default. And thats proven to work with Apple Silicon (M1 and M2 repectively).
But native arm64 building using MonoGame, atleast for the content pipeline is not possible as of missing dependencies compiled for arm64 stated by mrhelmut.