Fixing ld: warning: in /usr/local/lib/libz.dylib, file is not of required architecture 1

Posted by Sheldon Finlay on January 08, 2010

I banged my head on this stupid problem for months. It all came about after upgrading my Macbook from Leopard to Snow Leopard (OSX 1.6). I was plagued with this error here and there when I wanted to compile certain software (namely imagemagick and mysql) or install certain native Ruby gem. It was a nightmare, but it seemed I would have to live with it, until I could find the time to reinstall Snow Leopard from scratch.

Google reveals very little useful information for dealing with this error. Everyone seems to have the problem, and yet fixes seem quite elusive. I finally hit upon a fix that worked for me and I’ll share it here in case the solution also works for others. First thing you’ll want to do is install xCode, the developer SDK from Apple. Download the most recent version from the Apple Developer site, as the version on disk might be old. You’ll need the OSX 10.6 libraries. After xcode is installed go to the directory that the problemed libz.dylib file is found and rename it so you have a backup in case things get messed up worse and you need to restore it:

cd /usr/local/lib/libz.dylib
sudo mv libz.dylib libz.dylib.original

Now, when you installed xCode it should have also installed a recent version of libz.dylib in among the SDK files. So the next step is to copy that version of the file to replace the file we just renamed.

sudo cp -rf /Developer/SDKs/MacOSX10.6.sdk/usr/lib/libz.dylib .

That’s it. Go ahead and try to install that pesky ruby gem (rmagick) that wasn’t installing or compile ImageMagick. If you are lucky like me, it should work. I hope this saves some folks a lot of hair pulling. Let me know how it goes!

This may also work for some other dylib files that are problematic such as libexpat.dylib. Just take a look in the lib directory of the OSX 10.6 SDK and see if the file exists. Remember to things up before replacing swapping in the new files.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. rupert Wed, 03 Mar 2010 06:02:18 EST

    Thanks for this post. It saved me a lot of time. FYI, it seems my libz was installed in /opt/local/lib/ . Nevertheless, I copied the original libz.dylib from OSX10.6 as per your experience and it worked as well.

    -rwxrwxr-x 2 root admin 83040 28 Apr 2008 libz.1.2.3.dylib
    lrwxr-xr-x 1 root admin 16 28 Apr 2008 libz.1.dylib -> libz.1.2.3.dylib
    -rwxrwxr-x 2 root admin 83232 28 Apr 2008 libz.a
    -rwxr-xr-x 1 rupert admin 23852 3 Mar 21:53 libz.dylib

    Cheers,
    rupert

Comments