Compiling FreeImage in 64-bit on Snow Leopard

Posts


I recently tried to use the image_science gem for Ruby, but it didn’t work after installation because it was looking for FreeImage.h. Thinking it’d be an easy fix, I headed over to http://freeimage.sourceforge.net/ to go grab a copy of a binary file to install, but there wasn’t one.

Undeterred, I went to grab the source and compile it myself. It didn’t work. Eventually I figured there were two key issues:

  1. FreeImage’s source was prepared for Mac OS X 10.3 (Panther)
  2. FreeImage was trying to compile for i386 (32-bit) and my Ruby install is x86-64 (64-bit)

First problem is easy to fix, just replace both instances of /Developer/SDKs/MacOSX10.3.9.sdk with /Developer/SDKs/MacOSX10.6.sdk (or, 10.5 for Leopard, or 10.4u for Tiger).

The second part was a bit more fiddly because I wasn’t sure if order was important, so I started by replacing all instances of i386 and I386 with x86_64 and X86_64 respectively. Then, I replaced all instances of ppc and PPC with i386 and I386.

If you don’t want to worry about making all these changes, you can simply download my Makefile.osx here. It’s built for Snow Leopard, but it’s easy to change it for Leopard or Tiger.

13 thoughts on “Compiling FreeImage in 64-bit on Snow Leopard

  1. thanks very much! this was very helpful indeed :) this way it builds a fat library, that contains both intel archs – i386 and the 64bit _x86_64. i will see, if my 64bit project compiles.

  2. It certainly seems to have worked, yeah. I’ve not done much in the way of image related tasks, but all the warnings I was getting upon booting my Rails app have gone away.

  3. @Joshua: I’m not sure. I’m not very familiar with FreeImage, I just needed to get it working so that a Rails app I was working on could boot properly.

  4. Hi,
    I have problem compiling it with OSX SDKs. I always get warning, that there exist multiple definition of symbol in SDK /10.4., 10.5., 10.6./ and FreeImage.a compiled by this tutorial.

    Any ideas? Thx.

  5. I found that I was getting “make[1]: g++-4.0: No such file or directory” with your makefile. I have a new MBP, with a fresh XCode 4.0.1 install. I was able to track down that the error is from a missing symbolic link being setup – but searching for more than an hour was not showing me how to get that symbolic linksetup. So, noting that “g++” resolves to “i686-apple-darwin10-g++-4.2.1”, I changed your makefiles’s two references of “g++-4.0” to be “g++” and the two references to “gcc-4.0” to “gcc” and the compile works.

    Amy idea why I don’t have that symbolic link and how to get it?

  6. @Blake: I’ve not made the jump to Xcode 4 yet, I’m still on 3.2.5. You probably don’t want a g++-4.0 symlink pointing to a 4.2 binary though, it’s very likely there differences between the two which may cause you problems if a build does anything specific for 4.0. and figuring out the cause of those problems could be a nightmare. :)

    If you re-run the Xcode installer and customise the installation, I think you might be able to install g++-4.0 if you need it, but if you managed to build with 4.2 your solution of just having g++ in the Makefile (or perhaps changing it to g++-4.2) is probably better. Hope this helps!

  7. I have XCode4 and Lion, and I tried modify the makefile to support Lion (using the SDK 10.7) but I had no luck. Many “no such file or directory” messages relative to system headers (algorithms, float.h, and so)
    Any clue?
    Thanks.

  8. Hi! I have Xcode4.2 and Lion… I installed FreeImage but when I run a C-project i have this problem, he can’t execute a binary file —-> libfreeimage-3.15.4.dylib… any ideas? thanks
    ps. before this problem i had another problem:
    dyld: Library not loaded: Libfreeimage-3.14.1.dylib
    Referenced from: (Path to project)/build/Debug/(Project Name)
    Reason: image not found

Leave a Reply

Your email address will not be published. Required fields are marked *