当我不能设置`DYLD_LIBRARY_PATH`时,如何在macOS上可移植地安装ImageMagick? [英] How to install ImageMagick portably on macOS when I can't set `DYLD_LIBRARY_PATH`?

查看:438
本文介绍了当我不能设置`DYLD_LIBRARY_PATH`时,如何在macOS上可移植地安装ImageMagick?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为macOS(Mojave)开发一个命令行实用程序,该实用程序使用ImageMagick来操纵图像.我想以独立应用程序的形式共享它,以便其他人可以直接使用它,而不必安装任何其他dylib或框架. ImageMagick的Homebrew和MacPorts版本似乎已硬连接"到Mac的系统目录结构(分别为/usr/local/opt/local),以至于很难(不可能?)将ImageMagick及其委托库放入一个目录中.便携式应用程序捆绑包.因此,我直接使用的是 ImageMagick网站.

>

我按照该页面上的安装说明进行操作,然后将ImageMagick文件夹放在我的主目录中(位于~myname).按照指示,我做了export DYLD_LIBRARY_PATH="/Users/myname/ImageMagick-7.0.8/lib/".但是当我运行magick时,我收到一条错误消息:

$ ~myname/ImageMagick-7.0.8/bin/magick logo: test.jpg
dyld: Library not loaded: /ImageMagick-7.0.8/lib/libMagickCore-7.Q16HDRI.6.dylib
  Referenced from: /Users/myname/ImageMagick-7.0.8/bin/magick
  Reason: image not found
Abort trap: 6
$

很显然,即使按说明设置DYLD_LIBRARY_PATH时,也没有找到其dylib.实际上,看来我什至无法将DYLD_LIBRARY_PATH导出到环境中:

$ export MAGICK_HOME="/Users/myname/ImageMagick-7.0.8"
$ export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"
$ echo $DYLD_LIBRARY_PATH
/Users/myname/ImageMagick-7.0.8/lib
$ printenv | grep DYLD_LIBRARY_PATH
   # (nothing)
$ printenv | grep ImageMagick
MAGICK_HOME=/Users/myname/ImageMagick-7.0.8
$ 

这是怎么回事?如何使ImageMagick便携式?

解决方案

首先,当前在ImageMagick网站(版本7.0.8)上使用的IM版本适用于macOS High Sierra.因此,在Mojave上安装它遇到麻烦并不奇怪. (但是,FWIW,当前的Homebrew版本(IM 7)和MacPorts(IM 6)可以在Mojave上运行.但是,像您一样,我不知道如何使这些版本对委托的处理真正可移植.)/p>

您无法导出DYLD_LIBRARY_PATH的原因是因为Apple的系统完整性保护" (SIP),它已添加到新版本的macOS(El Capitan和更高版本)中.默认情况下,SIP禁止执行诸如更改env变量DYLD_LIBRARY_PATH之类的操作.尽管它可以禁用SIP ,Apple不建议这样做.

但是,您可以使用install_name_tool手动修改magick及其dylib,以便IM 7.0.8在Mojave上可以正常工作. (在bash中)方法如下:

# magick: set the correct path to libMagickCore.dylib 
install_name_tool -change \
    /ImageMagick-7.0.8/lib/libMagickCore-7.Q16HDRI.6.dylib \
    @executable_path/../lib/libMagickCore-7.Q16HDRI.6.dylib \
    /Users/myname/ImageMagick-7.0.8/bin/magick

# magick: set the correct path to libMagickWand.dylib 
install_name_tool -change \
    /ImageMagick-7.0.8/lib/libMagickWand-7.Q16HDRI.6.dylib \
    @executable_path/../lib/libMagickWand-7.Q16HDRI.6.dylib \
    /Users/myname/ImageMagick-7.0.8/bin/magick

# libMagickWand.dylib: set the correct ID
install_name_tool -id \
    @executable_path/../lib/libMagickWand-7.Q16HDRI.6.dylib \
    /Users/myname/ImageMagick-7.0.8/lib/libMagickWand-7.Q16HDRI.6.dylib

# libMagickWand.dylib: set the correct path
install_name_tool -change \
    /ImageMagick-7.0.8/lib/libMagickCore-7.Q16HDRI.6.dylib \
    @executable_path/../lib/libMagickCore-7.Q16HDRI.6.dylib \
    /Users/myname/ImageMagick-7.0.8/lib/libMagickWand-7.Q16HDRI.6.dylib

# libMagickCore.dylib: set the correct ID
install_name_tool -id \
    @executable_path/../lib/libMagickCore-7.Q16HDRI.6.dylib \
    /Users/myname/ImageMagick-7.0.8/lib/libMagickCore-7.Q16HDRI.6.dylib

现在可以使用了:

$ /Users/myname/ImageMagick-7.0.8/bin/magick logo: test.jpg
$ open test.jpg
$ # (Preview opens a nice picture of the ImageMagick logo.)

这将修改dylib相对于magick命令位置的路径.只要您保持ImageMagick文件夹的目录结构完整,它现在就应该是完全可移植的.

您可以轻松地将这五个install_name_tools命令放入一个小的bash脚本中.我将其留给读者作为练习. :)

I am developing a command line utility for macOS (Mojave) that manipulates images using ImageMagick. I want to share it as a standalone app in such a way that others can use it out-of-the-box without having to install any additional dylibs or frameworks. The Homebrew and MacPorts versions of ImageMagick seem to be "hardwired" to the Mac's system directory structure (/usr/local and /opt/local, respectively) in such a way that it's difficult (impossible?) to put ImageMagick and its delegate libraries into a portable application bundle. So I am instead using the distribution directly from the ImageMagick website.

I followed the installation instructions on that page and put the ImageMagick folder in my home directory (at ~myname). As instructed, I did export DYLD_LIBRARY_PATH="/Users/myname/ImageMagick-7.0.8/lib/". But when I run magick, I get an error message:

$ ~myname/ImageMagick-7.0.8/bin/magick logo: test.jpg
dyld: Library not loaded: /ImageMagick-7.0.8/lib/libMagickCore-7.Q16HDRI.6.dylib
  Referenced from: /Users/myname/ImageMagick-7.0.8/bin/magick
  Reason: image not found
Abort trap: 6
$

Clearly magick isn't finding its dylibs, even when I set DYLD_LIBRARY_PATH as instructed. It appears, in fact, that I can't even export DYLD_LIBRARY_PATH into the environment:

$ export MAGICK_HOME="/Users/myname/ImageMagick-7.0.8"
$ export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"
$ echo $DYLD_LIBRARY_PATH
/Users/myname/ImageMagick-7.0.8/lib
$ printenv | grep DYLD_LIBRARY_PATH
   # (nothing)
$ printenv | grep ImageMagick
MAGICK_HOME=/Users/myname/ImageMagick-7.0.8
$ 

What's going on? How can I make ImageMagick portable?

解决方案

First of all, the version of IM currently on the ImageMagick website (version 7.0.8) is for macOS High Sierra. It's therefore not too surprising that you're having trouble installing it on Mojave. (FWIW, the current Homebrew version (IM 7) and MacPorts (IM 6) do, however, work on Mojave. But, like you, I don't know how to make those versions' handling of the delegates truly portable.)

The reason you can't export DYLD_LIBRARY_PATH is because of Apple's "System Integrity Protection" (SIP), which it added to newer versions of macOS (El Capitan and later). By default, SIP prohibits doing things like changing the env variable DYLD_LIBRARY_PATH. Although it is possible to disable SIP, Apple does not recommend doing so.

You can, however, modify magick and its dylibs manually using install_name_tool so that IM 7.0.8 works fine on Mojave. Here's how (in bash):

# magick: set the correct path to libMagickCore.dylib 
install_name_tool -change \
    /ImageMagick-7.0.8/lib/libMagickCore-7.Q16HDRI.6.dylib \
    @executable_path/../lib/libMagickCore-7.Q16HDRI.6.dylib \
    /Users/myname/ImageMagick-7.0.8/bin/magick

# magick: set the correct path to libMagickWand.dylib 
install_name_tool -change \
    /ImageMagick-7.0.8/lib/libMagickWand-7.Q16HDRI.6.dylib \
    @executable_path/../lib/libMagickWand-7.Q16HDRI.6.dylib \
    /Users/myname/ImageMagick-7.0.8/bin/magick

# libMagickWand.dylib: set the correct ID
install_name_tool -id \
    @executable_path/../lib/libMagickWand-7.Q16HDRI.6.dylib \
    /Users/myname/ImageMagick-7.0.8/lib/libMagickWand-7.Q16HDRI.6.dylib

# libMagickWand.dylib: set the correct path
install_name_tool -change \
    /ImageMagick-7.0.8/lib/libMagickCore-7.Q16HDRI.6.dylib \
    @executable_path/../lib/libMagickCore-7.Q16HDRI.6.dylib \
    /Users/myname/ImageMagick-7.0.8/lib/libMagickWand-7.Q16HDRI.6.dylib

# libMagickCore.dylib: set the correct ID
install_name_tool -id \
    @executable_path/../lib/libMagickCore-7.Q16HDRI.6.dylib \
    /Users/myname/ImageMagick-7.0.8/lib/libMagickCore-7.Q16HDRI.6.dylib

Now it works:

$ /Users/myname/ImageMagick-7.0.8/bin/magick logo: test.jpg
$ open test.jpg
$ # (Preview opens a nice picture of the ImageMagick logo.)

This modifies the paths to the dylibs relative to the location of the magick command. As long as you keep the directory structure of the ImageMagick folder intact, it should now be completely portable.

You can easily put those five install_name_tools commands into a little bash script. I'll leave that as an exercise for the reader. :)

这篇关于当我不能设置`DYLD_LIBRARY_PATH`时,如何在macOS上可移植地安装ImageMagick?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆