Friday, December 27, 2013

Linux run time shared library path setting

此篇中,其目的是於corss platform中讓gdb找到正確的shared library path。
於native host環境中,執行程式時有時會有

error while loading shared libraries: ????????.so.?: cannot open
shared object file: No such file or directory

其可能的問題為不能找到需要的shared library,For examples...

$ pwd
/ImageMagick-6.5.7-10/utilities/.libs
$
$ ls
animate  composite  convert  identify  mogrify  stream
compare  conjure    display  import    montage
$
$ echo $LD_LIBRARY_PATH

$
$ ldd convert
 linux-gate.so.1 =>  (0xb7f23000)
 libMagickCore.so.2 => not found
 libMagickWand.so.2 => not found
 libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7efa000)
 libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7ef6000)
 libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7ed0000)
 libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7d6d000)
 /lib/ld-linux.so.2 (0xb7f24000)
$
$ ./convert
./convert: error while loading shared libraries: libMagickCore.so.2:
cannot open shared object file: No such file or directory
$

以上之中,由ldd command觀察convert所需要額外的library中,
沒找到libMagickCore.so.2,libMagickWand.so.2此兩的shared linary的所在位址,
所以會有"not found"的訊息出現。

若是以LD_LIBRARY_PATH來註冊額外shared library的路徑,即可解決...

$ export LD_LIBRARY_PATH=/ImageMagick-6.5.7-10/magick/.libs:/ImageMagick-6.5.7-10/wand/.libs
$
$ echo $LD_LIBRARY_PATH
/ImageMagick-6.5.7-10/magick/.libs:/ImageMagick-6.5.7-10/wand/.libs
$
$ ldd convert
 linux-gate.so.1 =>  (0xb7ee9000)
 libMagickCore.so.2 => /ImageMagick-6.5.7-10/magick/.libs/libMagickCore.so.2 (0xb7d66000)
 libMagickWand.so.2 => /ImageMagick-6.5.7-10/wand/.libs/libMagickWand.so.2 (0xb7c70000)
 libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7c49000)
 libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7c45000)
 libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7c1f000)
 libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7abc000)
 /lib/ld-linux.so.2 (0xb7eea000)
$

No comments:

Post a Comment