系统未建立
分类: LINUX
2016-11-02 17:25:55
原文地址:谈谈Linux下动态库查找路径的问题 作者:wjlkoorey258
[root@localhost ~]# cat /usr/local/lib/pkgconfig/librtmp.pc prefix=/usr/local exec_prefix=${prefix} libdir=${exec_prefix}/lib incdir=${prefix}/include Name: librtmp Description: RTMP implementation Version: v2.3 Requires: libssl,libcrypto URL: Libs: -L${libdir} -lrtmp -lz Cflags: -I${incdir} |
[root@localhost ~]# pkg-config --cflags librtmp -I/usr/local/include [root@localhost ~]# pkg-config --libs librtmp -L/usr/local/lib -lrtmp -lz -lssl -lcrypto |
pkg-config retrieves information about packages from special metadata files. These files are named after the package, with the extension .pc. By default, pkg-config looks in the directory prefix/lib/pkgconfig for these files; it will also look in the colon-separated (on Windows, semicolon-separated) list of directories specified by the PKG_CONFIG_PATH environment variable. |
PKG_CONFIG_PATH A colon-separated (on Windows, semicolon-separated) list of directories to search for .pc files. The default directory will always be searched after searching the path; the default is libdir/pkg-config:datadir/pkgconfig where libdir is the libdir where pkg-config and datadir is the datadir where pkg-config was installed. |
export PKG_CONFIG_PATH=/your/local/path:$PKG_CONFIG_PATH |
[root@localhost ~]# echo $LD_LIBRARY_PATH //嘛也没有 [root@localhost ~]# ldd /usr/local/bin/ffmpeg linux-gate.so.1 => (0x00914000) libavdevice.so.54 => /usr/local/lib/libavdevice.so.54 (0x007d0000) libavfilter.so.3 => /usr/local/lib/libavfilter.so.3 (0x001f3000) libavformat.so.54 => /usr/local/lib/libavformat.so.54 (0x002b5000) libavcodec.so.54 => /usr/local/lib/libavcodec.so.54 (0xb68dd000) libpostproc.so.52 => /usr/local/lib/libpostproc.so.52 (0x0083c000) libswresample.so.0 => /usr/local/lib/libswresample.so.0 (0x00a91000) libswscale.so.2 => /usr/local/lib/libswscale.so.2 (0x00d80000) libavutil.so.52 => /usr/local/lib/libavutil.so.52 (0x001a7000) libm.so.6 => /lib/libm.so.6 (0x0058b000) libpthread.so.0 => /lib/libpthread.so.0 (0x001d7000) libc.so.6 => /lib/libc.so.6 (0x005e2000) libasound.so.2 => /lib/libasound.so.2 (0x00ec5000) libdc1394.so.22 => /usr/local/lib/libdc1394.so.22 (0x00116000) librt.so.1 => /lib/librt.so.1 (0x00184000) libfreetype.so => /usr/local/lib/libfreetype.so (0x00411000) libass.so.4 => /usr/local/lib/libass.so.4 (0x0091a000) libssl.so.1.0.0 => /usr/local/lib/libssl.so.1.0.0 (0x0048c000) libcrypto.so.1.0.0 => /usr/local/lib/libcrypto.so.1.0.0 (0x00aa8000) librtmp.so.0 => /usr/local/lib/librtmp.so.0 (0x009dd000) libz.so.1 => /lib/libz.so.1 (0x0018d000) libx264.so.132 => /usr/local/lib/libx264.so.132 (0x00fb1000) libvorbisenc.so.2 => /usr/local/lib/libvorbisenc.so.2 (0x0194d000) libvorbis.so.0 => /usr/local/lib/libvorbis.so.0 (0x004e5000) libvo-aacenc.so.0 => /usr/local/lib/libvo-aacenc.so.0 (0x00799000) libtwolame.so.0 => /usr/local/lib/libtwolame.so.0 (0x0050d000) libtheoraenc.so.1 => /usr/local/lib/libtheoraenc.so.1 (0x0052d000) libtheoradec.so.1 => /usr/local/lib/libtheoradec.so.1 (0x00779000) libspeex.so.1 => /usr/local/lib/libspeex.so.1 (0x00c94000) libmp3lame.so.0 => /usr/local/lib/libmp3lame.so.0 (0x0088c000) libfaac.so.0 => /usr/local/lib/libfaac.so.0 (0x00573000) /lib/ld-linux.so.2 (0x005c2000) libdl.so.2 => /lib/libdl.so.2 (0x001a1000) libraw1394.so.11 => /usr/local/lib/libraw1394.so.11 (0x005b5000) libfribidi.so.0 => /usr/local/lib/libfribidi.so.0 (0x007b5000) libfontconfig.so.1 => /usr/local/lib/libfontconfig.so.1 (0x007ea000) libogg.so.0 => /usr/local/lib/libogg.so.0 (0x00583000) libexpat.so.1 => /lib/libexpat.so.1 (0x00933000) |
[root@localhost ~]# ldd /usr/local/bin/ffmpeg linux-gate.so.1 => (0x00249000) libavdevice.so.54 => /usr/local/lib/libavdevice.so.54 (0x00e12000) libavfilter.so.3 => /usr/local/lib/libavfilter.so.3 (0x00ccd000) libavformat.so.54 => /usr/local/lib/libavformat.so.54 (0x00891000) libavcodec.so.54 => /usr/local/lib/libavcodec.so.54 (0xb6877000) libpostproc.so.52 => /usr/local/lib/libpostproc.so.52 (0x001a6000) libswresample.so.0 => /usr/local/lib/libswresample.so.0 (0x00b8f000) libswscale.so.2 => /usr/local/lib/libswscale.so.2 (0x0024a000) libavutil.so.52 => /usr/local/lib/libavutil.so.52 (0x005d7000) libm.so.6 => /lib/libm.so.6 (0x007ad000) libpthread.so.0 => /lib/libpthread.so.0 (0x001f6000) libc.so.6 => /lib/libc.so.6 (0x0029f000) libasound.so.2 => /lib/libasound.so.2 (0x00604000) libdc1394.so.22 => /usr/local/lib/libdc1394.so.22 (0x00436000) librt.so.1 => /lib/librt.so.1 (0x00a06000) libfreetype.so => /usr/local/lib/libfreetype.so (0x0052d000) libass.so.4 => /usr/local/lib/libass.so.4 (0x00211000) libssl.so.1.0.0 => /usr/local/lib/libssl.so.1.0.0 (0x00eed000) libcrypto.so.1.0.0 => /usr/local/lib/libcrypto.so.1.0.0 (0x00f46000) librtmp.so.0 => /usr/local/lib/librtmp.so.0 (0x004b9000) libz.so.1 => /lib/libz.so.1 (0x0022a000) libx264.so.132 => /usr/local/lib/libx264.so.132 (0x0765d000) libvorbisenc.so.2 => /usr/local/lib/libvorbisenc.so.2 (0x00a0f000) libvorbis.so.0 => /usr/local/lib/libvorbis.so.0 (0x004ce000) libvo-aacenc.so.0 => /usr/local/lib/libvo-aacenc.so.0 (0x005a8000) libtwolame.so.0 => /usr/local/lib/libtwolame.so.0 (0x006f0000) libtheoraenc.so.1 => /usr/local/lib/libtheoraenc.so.1 (0x00710000) libtheoradec.so.1 => /usr/local/lib/libtheoradec.so.1 (0x00756000) libspeex.so.1 => /usr/local/lib/libspeex.so.1 (0x00770000) libmp3lame.so.0 => not found //果然飘红了 :) libfaac.so.0 => /usr/local/lib/libfaac.so.0 (0x004a4000) /lib/ld-linux.so.2 (0x0050d000) libdl.so.2 => /lib/libdl.so.2 (0x0023e000) libraw1394.so.11 => /usr/local/lib/libraw1394.so.11 (0x004f6000) libfribidi.so.0 => /usr/local/lib/libfribidi.so.0 (0x0078a000) libfontconfig.so.1 => /usr/local/lib/libfontconfig.so.1 (0x007d7000) libogg.so.0 => /usr/local/lib/libogg.so.0 (0x00243000) libexpat.so.1 => /lib/libexpat.so.1 (0x00806000) [root@localhost ~]# ffmpeg --help ffmpeg: error while loading shared libraries: libmp3lame.so.0: cannot open shared object file: No such file or directory //此时ffmpeg当然运行不起来 |
[root@localhost opt]# export LD_LIBRARY_PATH=/opt:$LD_LIBRARY_PATH [root@localhost opt]# [root@localhost opt]# ldd /usr/local/bin/ffmpeg linux-gate.so.1 => (0x00136000) libavdevice.so.54 => /usr/local/lib/libavdevice.so.54 (0x00552000) libavfilter.so.3 => /usr/local/lib/libavfilter.so.3 (0x00655000) libavformat.so.54 => /usr/local/lib/libavformat.so.54 (0x00243000) libavcodec.so.54 => /usr/local/lib/libavcodec.so.54 (0xb68a7000) libpostproc.so.52 => /usr/local/lib/libpostproc.so.52 (0x00137000) libswresample.so.0 => /usr/local/lib/libswresample.so.0 (0x00187000) libswscale.so.2 => /usr/local/lib/libswscale.so.2 (0x0047e000) libavutil.so.52 => /usr/local/lib/libavutil.so.52 (0x00a9d000) libm.so.6 => /lib/libm.so.6 (0x00af9000) libpthread.so.0 => /lib/libpthread.so.0 (0x00823000) libc.so.6 => /lib/libc.so.6 (0x0083e000) libasound.so.2 => /lib/libasound.so.2 (0x0055f000) libdc1394.so.22 => /usr/local/lib/libdc1394.so.22 (0x0019e000) librt.so.1 => /lib/librt.so.1 (0x00b3c000) libfreetype.so => /usr/local/lib/libfreetype.so (0x0039f000) libass.so.4 => /usr/local/lib/libass.so.4 (0x00f67000) libssl.so.1.0.0 => /usr/local/lib/libssl.so.1.0.0 (0x00cb3000) libcrypto.so.1.0.0 => /usr/local/lib/libcrypto.so.1.0.0 (0x00d0c000) librtmp.so.0 => /usr/local/lib/librtmp.so.0 (0x0020c000) libz.so.1 => /lib/libz.so.1 (0x00c77000) libx264.so.132 => /usr/local/lib/libx264.so.132 (0x00f80000) libvorbisenc.so.2 => /usr/local/lib/libvorbisenc.so.2 (0x07c66000) libvorbis.so.0 => /usr/local/lib/libvorbis.so.0 (0x0041a000) libvo-aacenc.so.0 => /usr/local/lib/libvo-aacenc.so.0 (0x0076c000) libtwolame.so.0 => /usr/local/lib/libtwolame.so.0 (0x004fe000) libtheoraenc.so.1 => /usr/local/lib/libtheoraenc.so.1 (0x00717000) libtheoradec.so.1 => /usr/local/lib/libtheoradec.so.1 (0x00f0c000) libspeex.so.1 => /usr/local/lib/libspeex.so.1 (0x00221000) libmp3lame.so.0 => not found //纳尼??!!! libfaac.so.0 => /usr/local/lib/libfaac.so.0 (0x00124000) /lib/ld-linux.so.2 (0x00bad000) libdl.so.2 => /lib/libdl.so.2 (0x0023b000) libraw1394.so.11 => /usr/local/lib/libraw1394.so.11 (0x007b6000) libfribidi.so.0 => /usr/local/lib/libfribidi.so.0 (0x00442000) libfontconfig.so.1 => /usr/local/lib/libfontconfig.so.1 (0x0051e000) libogg.so.0 => /usr/local/lib/libogg.so.0 (0x009f7000) libexpat.so.1 => /lib/libexpat.so.1 (0x00b60000) |
[root@localhost opt]# ls libmp3lame.so.0.0.0 [root@localhost opt]# ln -s libmp3lame.so.0.0.0 libmp3lame.so.0 [root@localhost opt]# ll total 316 lrwxrwxrwx. 1 root root 19 Dec 7 23:27 libmp3lame.so.0 -> libmp3lame.so.0.0.0 -rwxr-xr-x. 1 root root 321228 Dec 7 23:25 libmp3lame.so.0.0.0 [root@localhost opt]# ldd /usr/local/bin/ffmpeg linux-gate.so.1 => (0x00cc4000) libavdevice.so.54 => /usr/local/lib/libavdevice.so.54 (0x00577000) libavfilter.so.3 => /usr/local/lib/libavfilter.so.3 (0x00e3f000) libavformat.so.54 => /usr/local/lib/libavformat.so.54 (0x00202000) libavcodec.so.54 => /usr/local/lib/libavcodec.so.54 (0x00f01000) libpostproc.so.52 => /usr/local/lib/libpostproc.so.52 (0x00170000) libswresample.so.0 => /usr/local/lib/libswresample.so.0 (0x00750000) libswscale.so.2 => /usr/local/lib/libswscale.so.2 (0x0035e000) libavutil.so.52 => /usr/local/lib/libavutil.so.52 (0x005ba000) libm.so.6 => /lib/libm.so.6 (0x00452000) libpthread.so.0 => /lib/libpthread.so.0 (0x001c0000) libc.so.6 => /lib/libc.so.6 (0x008c2000) libasound.so.2 => /lib/libasound.so.2 (0x0047c000) libdc1394.so.22 => /usr/local/lib/libdc1394.so.22 (0x003d6000) librt.so.1 => /lib/librt.so.1 (0x00db3000) libfreetype.so => /usr/local/lib/libfreetype.so (0x00a80000) libass.so.4 => /usr/local/lib/libass.so.4 (0x001db000) libssl.so.1.0.0 => /usr/local/lib/libssl.so.1.0.0 (0x005e7000) libcrypto.so.1.0.0 => /usr/local/lib/libcrypto.so.1.0.0 (0x00afb000) librtmp.so.0 => /usr/local/lib/librtmp.so.0 (0x00584000) libz.so.1 => /lib/libz.so.1 (0x00599000) libx264.so.132 => /usr/local/lib/libx264.so.132 (0x02bc9000) libvorbisenc.so.2 => /usr/local/lib/libvorbisenc.so.2 (0x05ccd000) libvorbis.so.0 => /usr/local/lib/libvorbis.so.0 (0x00640000) libvo-aacenc.so.0 => /usr/local/lib/libvo-aacenc.so.0 (0x00834000) libtwolame.so.0 => /usr/local/lib/libtwolame.so.0 (0x00668000) libtheoraenc.so.1 => /usr/local/lib/libtheoraenc.so.1 (0x00688000) libtheoradec.so.1 => /usr/local/lib/libtheoradec.so.1 (0x006ce000) libspeex.so.1 => /usr/local/lib/libspeex.so.1 (0x00815000) libmp3lame.so.0 => /opt/libmp3lame.so.0 (0x00767000) //终于圆满了:) libfaac.so.0 => /usr/local/lib/libfaac.so.0 (0x006e8000) /lib/ld-linux.so.2 (0x003b6000) libdl.so.2 => /lib/libdl.so.2 (0x001f4000) libraw1394.so.11 => /usr/local/lib/libraw1394.so.11 (0x00444000) libfribidi.so.0 => /usr/local/lib/libfribidi.so.0 (0x006f8000) libfontconfig.so.1 => /usr/local/lib/libfontconfig.so.1 (0x00710000) libogg.so.0 => /usr/local/lib/libogg.so.0 (0x001f9000) libexpat.so.1 => /lib/libexpat.so.1 (0x007e3000) |