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

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 GMT+5

    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

  2. Jordan Brough Fri, 26 Mar 2010 22:37:38 GMT+5

    Thank you, I was banging my head trying to get the mysql gem installed after upgrading to Snow Leopard as well and this works great.

  3. Jordan Brough Fri, 26 Mar 2010 22:56:17 GMT+5

    Note: I had to do the same for libz.1.dylib + libz.1.2.3.dylib to get the pg (postgres) gem to install.

  4. Alex Chaffee Fri, 16 Jul 2010 11:09:01 GMT+5

    Are you using MacPorts? You may need to migrate your old binaries. See the MacPorts migration docs:

    https://trac.macports.org/wiki/Migration

    And here’s a script that may ease the pain:

    http://andyic.org/wordpress/index.php/2010/06/macports-migration/

  5. Josh Fri, 03 Sep 2010 18:07:24 GMT+5

    Why not just delete the bad copy of zlib? A fresh install of OS X has nothing in /usr/local.

  6. Yann Mon, 06 Sep 2010 11:57:24 GMT+5

    Thanks a lot! I was having a problem compiling nokogori native extensions, copying libz.1.dylib as you suggest solves the problem. I didn’t try Josh’s technique.

  7. Mason Simon Wed, 16 Feb 2011 18:20:49 GMT+5

    Thanks! This fixed my nokogiri problem too. I did those steps for libz.1.dylib + libz.1.2.3.dylib as well, like Jordan Brough did.

  8. Brent Thu, 03 Mar 2011 18:53:59 GMT+5

    Thank you. My recent attempt to compile Io did not like the libz I had. It complained about it not being x86_64. Your tip lead me to a 64 bit libz that mad it happy.

  9. Vicki Fri, 15 Apr 2011 01:15:27 GMT+5

    THANK YOU SO MUCH. I had to do this to fix my nokogiri problem as well. You’re a legend!

  10. Collin VanDyck Thu, 23 Jun 2011 11:20:45 GMT+5

    Thanks for saving me a lot of time.

  11. Matty Sun, 07 Aug 2011 00:12:20 GMT+5

    Thanks man! I spent 4 hours on this issue. Luckily I stopped by your site. thanks

Comments