Skip to content

Instantly share code, notes, and snippets.

@msikma
Last active June 16, 2019 21:55
Show Gist options
  • Save msikma/237dff366827c34e2ad95451b6083d8b to your computer and use it in GitHub Desktop.
Save msikma/237dff366827c34e2ad95451b6083d8b to your computer and use it in GitHub Desktop.

When compiling FreeImage/libfreeimage on Mac OS X, some changes to the makefile are needed for it to work. This guide was written on 2019-06-16 and I was using the trunk from r1815. (The "trunk" is basically SVN's version of the master branch, for those of you who only know Git.)

Before you start, did you know you can use Homebrew to avoid having to compile it at all? It's available here:

brew install freeimage

For those who want to build it, read on.


First get the source:

svn checkout https://svn.code.sf.net/p/freeimage/svn/ freeimage-svn

Use the trunk directory. Edit Makefile.srcs and add ./Source/LibJXR/image/sys/perfTimerANSI.c to the SRCS variable.

In Makefile.osx there are two comments that read "ONLY STATIC AND 64 BIT // START" and "STATIC AND DYNAMIC 32 and 64 BIT // START". The first block is active, and the second one is commented out. Reverse this: make sure the first block is commented out (lines 54-65 at this time of writing) and the second block is active (lines 67-79).

After removing the comment lines, there should be a space in front of the line starting with FreeImage:. Remove it. Also remove the extra space rightmost rule—this is very important. Changes:

-# FreeImage: $(STATICLIB) $(SHAREDLIB )
+FreeImage: $(STATICLIB) $(SHAREDLIB)

Now we need to remove all rules to make i386 libraries from the static lib and shared lib rules (respectively lines 76 and 87, and the lines directly below them, in this version):

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

# ...

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

If you've unsuccessfully attempted to build before, run make clean to remove the old attempt.

Now when running make it should successfully make a dylib file, and allow you to run make install.

Links

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