如何把编译好的工具迁移到另一台机器上去,有时候我们会遇到这样的问题,怎样解决库文件的依赖问题就需要我们按照出错提示去解决问题了,我以ImageMagick为例做下讲解。
如何编译安装ImageMagick环境,参照我的上一篇文章ImageMagick的安装和使用案例,链接:
http://xiaoxiaozhou.blog.51cto.com/4681537/1903499
在本文中两台主机分别用server1和server2标识,server1为安装编译好ImageMagick的系统,server2则为未编译安装ImageMagick的系统。
首先把server1上编译好的文件传到server2上,下面为server2上已经接收到的文件
~/sxzhou> ll
total 40
drwxr-xr-x 7 was_wcm was_wcm 4096 Mar 3 10:30 ImageMagick
drwxr-xr-x 8 was_wcm was_wcm 4096 Mar 3 10:30 libpng-1.5.8
执行出错:
~/sxzhou/ImageMagick/bin> ./convert
./convert: error while loading shared libraries: libMagickCore-7.Q16HDRI.so.2: cannot open shared object file: No such file or directory
可以发现是库文件缺失,把缺失的库文件拷到server2上就可以了
server1上查找缺失的库文件
# find -name libMagickCore-7.Q16HDRI.so.2
./usr/local/ImageMagick/lib/libMagickCore-7.Q16HDRI.so.2
./home/sxzhouhou/ImageMagick-7.0.5-0/MagickCore/.libs/libMagickCore-7.Q16HDRI.so.2
可以发现除了安装目录下/usr/local/下也有库文件,拷贝/usr/local/ImageMagick到server2的/usr/local目录下
再次执行出错:
/home/was_wcm/sxzhou/ImageMagick/bin # ./convert
./convert: error while loading shared libraries: libpng15.so.15: cannot open shared object file: No such file or director
server1上查找
# find / -name libpng15.so.15
/usr/local/lib/libpng15.so.15
/home/sxzhouhou/libpng-1.5.8/.libs/libpng15.so.15
server1上png相关的库文件
/usr/local/lib # ls libpng
libpng.a libpng.so libpng15.la libpng15.so.15 libpng.la libpng15.a libpng15.so libpng15.so.15.8.0
拷贝server1上png相关的库文件到server2的/usr/local/lib/目录下
再次执行出错:
/home/was_wcm/sxzhou/ImageMagick/bin # ./convert
./convert: error while loading shared libraries: libpng15.so.15: cannot open shared object file: No such file or directory
/home/was_wcm/sxzhou/ImageMagick/bin # ldconfig /usr/local/lib
ldconfig: /usr/local/lib/libpng15.so.15 is not a symbolic link
出现上面的错误提示的原因是libpng15.so.15正常情况下是一个符号链接,所以修改其为符号链接即可
查看源主机的文件
/usr/local/lib # ll libpng15.so.15
lrwxrwxrwx 1 root root 18 Mar 2 14:21 libpng15.so.15 -> libpng15.so.15.8.0
而现主机文件
/usr/local/lib # ll libpng15.so.15
-rwxr-xr-x 1 root root 610183 Mar 3 10:44 libpng15.so.15
server2上做以下操作
/usr/local/lib # mv libpng15.so.15 libpng15.so.15.8.0
/usr/local/lib # ln -s libpng15.so.15.8.0 libpng15.so.15
/usr/local/lib # ll libpng15.so.15
lrwxrwxrwx 1 root root 18 Mar 3 10:59 libpng15.so.15 -> libpng15.so.15.8.0
终于可以使用了!!!
/home/was_wcm/sxzhou/ImageMagick/bin # ./convert
Version: ImageMagick 7.0.5-0 Q16 x86_64 2017-03-02 http://www.p_w_picpathmagick.org
Copyright: ? 1999-2017 ImageMagick Studio LLC
License: http://www.p_w_picpathmagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP
Delegates (built-in): png zlib