Search code examples
rubymacosimagemagickrmagickxz

ImageMagick unable to start because of incompatible version of liblzma


I'm trying to setup a server to serve a Ruby app that uses ImageMagick and the RMagick gem. The server is running OS X 10.10. I have another server that is running the same versions of everything (OS, ImageMagick, xz, and the RMagick gem) that is working as expected.

However, everytime I try to serve the app from the new server, I receive an error saying that 'Web application could not be started', with the following trace:

dlopen(/Users/user/.rvm/gems/ruby-2.1.5@app/extensions/x86_64-darwin-14/2.1.0-static/rmagick-2.15.4/RMagick2.bundle, 9):
   Library not loaded: /usr/local/lib/liblzma.5.dylib
Referenced from: /usr/local/opt/imagemagick/lib/libMagickCore-6.Q16.2.dylib
Reason: Incompatible library version: libMagickCore-6.Q16.2.dylib requires version 8.0.0 or later, but liblzma.5.dylib provides version 6.0.0 - /Users/user/.rvm/gems/ruby-2.1.5@app/extensions/x86_64-darwin-14/2.1.0-static/rmagick-2.15.4/RMagick2.bundle (LoadError)

Basically, it looks like ImageMagick is looking for version 8.0.0 of liblzma, but only finding version 6.0.0.

ImageMagick and xz are installed using Homebrew -- according to other answered questions, the xz package should have liblzma 8.0.0.

I have tried uninstalling and re-installing ImageMagick, the rmagick gem, and xz (the package the liblzma is served from) to no avail.

Please let me know if you need any more information.


EDIT: The output of running otool on /usr/local/lib/liblzma.5.dylib:

otool -L /usr/local/lib/liblzma.5.dylib
/usr/local/lib/liblzma.5.dylib:
  /usr/local/opt/xz/lib/liblzma.5.dylib (compatibility version 8.0.0, current version 8.2.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

I'm even more confused.. it is clearly over version 8.0.0.


Solution

  • Ok, I figured this out.

    For some reason, ImageMagick, rmagick, and/or passenger were finding the system copy of liblzma.5.dylib located at /usr/lib, rather than the copy homebrew setup at /usr/local/lib (despite the error message saying it was looking in /usr/local/lib).

    I figured this out by running the otool command on both copies of liblzma.5.dylib.

    For /usr/local/lib/liblzma.5.dylib:

    otool -L /usr/local/lib/liblzma.5.dylib
    /usr/local/lib/liblzma.5.dylib:
      /usr/local/opt/xz/lib/liblzma.5.dylib (compatibility version 8.0.0, current version 8.2.0)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
    

    For /usr/lib/liblzma.5.dylib:

    otool -L /usr/lib/liblzma.5.dylib
    /usr/lib/liblzma.5.dylib:
      /usr/lib/liblzma.5.dylib (compatibility version 6.0.0, current version 6.3.0)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
    

    After a system restart, the ImageMagick/rmagick/passenger started to use the right copy of liblzma.5.dylib.