Dynamic libraries find path-related problems, which are generally divided into two categories
First Class: The source code to compile the program when you can not find a dependency package problem, and if you happen to be in accordance with its requirements are indeed true, true, heaven knows to the dependency library to install, it also gives you to play mixed, guilty two, there is a toss of the dead not to die, it makes people really angry son do not play a place, If Linux at this time gravitated, you do not want to smoke it ya two big mouth;
The second type: is in the run the program, obviously the program needs the dependency package has been installed properly, can run when people tell you that "error while loading shared Libraries:libxxx.so.y:cannot open Shared object File:no such file or directory ", whatever you do is useless. At this point, if you want to "withdraw, buddy, Linux too TM Bully, do not take so much fun," then you are wrong, as long as you hold the "good things will happen" and "approach is always more than the problem" of the belief persist, you will be successful. The meaning of the words is a little self-deception, the taste of the spirit of opium in the inside, but it is really such a reason.
Issue 1: Using the source code installer
To install the program through the code package, the main use of the "three big strides" strategy: Configure, make and make install. The most problematic is in the Configure stage, many beginners because do not know configure so many parameters how to use, so often for the sake of convenience, a simple "./configure" Down, 80% or 90% can be successful, But the problem tends to be on top of the remaining 10%. This allows us to believe once again that the occurrence of a small probability event has a profound impact on things. In the Configure phase of the installation, in order to detect whether the installation installation environment is satisfied, it is usually through a tool called Pkg-config to detect the existence of the dynamic libraries it needs to rely on, which we have already known in the previous blog post. Pkg-config is typically located in the/usr/bin directory and is an executable program. In the Configure phase, it is common to use pkg-config to determine whether a dependent dynamic library exists. Now the question is, how is this tool judged? What is the basis of it? When these two problems are understood, the truth is clear.
generally when we install a program, if it provides a dynamic library function, in the source code will have one or more files ending with a PC, when the finished make install after the PC files are copied to the ${prefix}/lib/pkgconfig directory, The prefix here is that we specified by the configuration parameter--prefix in the Configure phase, which is/usr/local, so the PC files will eventually be copied to the/usr/local/lib/pkgconfig directory. Some people may ask, what is the use of these PC files? Let's open up a few to look at:
[Email protected] ~]# cat/usr/local/lib/pkgconfig/librtmp.pcprefix=/usr/localexec_prefix=${prefix}libdir=${exec_ Prefix}/libincdir=${prefix}/includename:librtmpdescription:rtmp Implementationversion:v2.3requires:libssl, Libcryptourl:http://rtmpdump.mplayerhq.hulibs:-l${libdir}-lrtmp-lzcflags:-i${incdir}
The main focus of our configure phase is on the two items of Libs and cflags, and if you execute these two commands at this point, you are fully aware of the following:
[[email protected] ~]# pkg-config--cflags librtmp-i/usr/local/include[[email protected] ~]# pkg-config--libs librtmp-l /usr/local/lib-lrtmp-lz-lssl-lcrypto
In other words, pkg-config the parameters we need to specify in the makefile to compile and link from the manual hard-coded mode to automatic completion, saving a lot of cross-platform portability compatibility issues, we have to thank others 18 generation of children ancestors. If we're going to build a package that relies on librtmp this dynamic library, then this check on my system is passed. Of course this is only the first step, the detection is not necessarily compatible, here we only discuss can find the problem of relying on the library, compatibility problem that is not a matter, people want what version you are born to wait is, this has no discussion, the best also don't discuss, fair trade, otherwise the consequences are very serious. Well, what if I can't find a library. The premise is that you really have installed the library it needs, do not think, for only one reason, pkg-config can not find this library corresponding to the PC file. Why can not find it, the reason is two points:
1, Pkg-config Search all it thinks the right directory is not looking for the library corresponding to the whereabouts of the PC file;
2. This library does not provide its PC file at all when it is published.
Here, we seriously "protest, despise + boycott" The second case of the package, but also try to avoid it, a man out of the mix is not tell, certainly not a better place to go. So, there's only one thing left: where is the search path for pkg-config?
Pkg-config older version, by default will go to/usr/lib/pkgconfig,/usr/loca/lib/pkgconfig,/usr/share/pkgconfig and other directories to search for PC files, As far as I know in the 0.23 and later version of the Pkg-config in the source code has no hard-coded components of the default search path, as to the specific version from which I did not pursue, but also hope to have a friend to share. Instead, when you look at Pkg-config's Man Handbook, there's the following passage:
Pkg-config retrieves information about packages from special metadata files. These files is named after the package, with the extension. PC. By default, Pkg-config looks in the directory prefix/lib/pkgconfig for these files; It'll also look in the colon-separated (on Windows, semicolon-separated) List of directories specified by the Pkg_config _path environment variable. |
And this supplement:
Pkg_config_path A colon-separated (on Windows, semicolon-separated) lists of directories to search for. pc files. The default directory is always being searched after searching the path; The default is libdir/pkg-config:datadir/pkgconfig where Libdir is the libdir where pkg-config and data Dir is the DataDir where Pkg-config was installed. |
The above mentioned prefix, Libdir and DataDir are set when the Pkg-config is installed, the situation is as follows:
1, if you are installed through the Yum and RPM packages
Prefix=/usr
Libdir=${prefix}/lib=/usr/lib
Datadir=${prefix}/share=/usr/share
2, if you are installed through the source package, and do not specify the value of prefix (the same as 1 specified)
Prefix=/usr/local
Libdir=${prefix}/lib=/usr/local/lib
Datadir=${prefix}/share=/usr/local/share
Pkg-config The default search path when looking up information for the corresponding package is already clear, a bit wrong, not ${libdir}/pkg-config, but should be ${libdir}/pkgconfig and ${datadir}/pkgconfig. If the PC files for your package are not in these two directories, pkg-config must not be found. Now that the reasons have been found, the solution is varied.
programme I: We can use the--prefix parameter to assign the installation directory to/USR in the Configure phase when we install our dependent package;
Scenario Two: It is also possible to indicate to pkg-config the path of our own PC files by using an environment variable called Pkg_config_path, as mentioned above, but note that the path specified by Pkg_config_path is of high priority. Pkg-config will search first, then search the default path.
The advantage of the former is that after the installation of software through the source of a lot of trouble, the disadvantage is that the user's own software packages and systems mixed together inconvenient management, so the actual use, the latter with more.
There are two ways to achieve this in the actual operation of scenario two:
1. For cases without root privileges, most of the cases are performed:
Export Pkg_config_path=/your/local/path: $PKG _config_path
Then, there is absolutely no problem when configure.
2, in the user's home directory in the. bash_profile file or the end of the system file/etc/profile add the above line is also available.
At this point, the first case of the dynamic library lookup problem is completely solved. For more details on PC files, you can refer to http://people.freedesktop.org/~dbn/pkg-config-guide.html; a friend who wants to learn more about Pkg-config Tools suggests looking at the man Handbook.
Issue 2: The program is running with LIBXXX.SO.Y = not found
This situation, in my previous blog post "Linux system dynamic library and static library that point of the matter" has been mentioned in part, here to add it complete. In that blog post, I used the config file or "LdconfigThe path where the dynamic library resides"Solution is also a 99%-case solution, which is a solution for users with root privileges. When running the software without root privileges, Linux also provides us with an environment variable named Ld_library_path to solve the runtime dynamic library lookup path solution. Similarly, the path specified by this environment variable will be/lib/ld-2.12.so by the loader first, then the dynamic library cache file/etc/ld.so.cache, elegant demeanor is ld_library_path to Rob,/etc/ Ld.so.cache said he was unhappy. For the LD_LIBRARY_PATH environment variable This situation, is definitely temporarily no longer temporary solution, if only for testing, with export as a solution to pkg_config_path the same way clean and neat on the line,do not in the actual production on-line operation environment in the "Export ld_library_path= ..." Add to. Bash_profile or/etc/profile., or you will regret that your intestines are green.
In fact, Pkg_config_path and Ld_library_path are often misused by many people, especially the novice in solving problems, but also indiscriminately, caught is a crazy export, according to the actual situation, luck may be the problem is really solved, A little back to toss a day and a half stay is also white busy. In fact, if you leave a snack, it is easy to understand:
Pkg_config_path from the literal meaning of translation, is "Package configuration path", this is not very obvious, compile software if there is not found in the dependent dynamic library when it is all rely on pkg_config_path;
Ld_library_path also very straightforward "loader library path", LD is a shorthand for loader, in the blog "section error in the end is where doer" I also mentioned that in the Linux system to start a program is called loading, When a program executes, it relies more or less on dynamic libraries (except statically compiled ones). When you use the LDDExecutable program name"View a dynamic library on which software starts, and if the output item has a" libxxx.so.y=> not found "item, you cannot run this software 100%.
Don't believe us to do an experiment:
[[email protected] ~]# echo $LD _library_path//Well no [[email protected] ~]# ldd/usr/local/bin/ffmpeg li Nux-gate.so.1 = (0x00914000) libavdevice.so.54 =/usr/local/lib/libavdevice.so.54 (0x007d0000) Liba Vfilter.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 =&G T /usr/local/lib/libpostproc.so.52 (0x0083c000) libswresample.so.0 =/usr/local/lib/libswresample.so.0 (0x00a9100 0) libswscale.so.2 =/usr/local/lib/libswscale.so.2 (0x00d80000) libavutil.so.52 =/usr/local/lib/li bavutil.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 (0x0 0ec5000) LIBDC1394.so.22 =/usr/local/lib/libdc1394.so.22 (0x00116000) librt.so.1 =/lib/librt.so.1 (0x00184000) L ibfreetype.so =/usr/local/lib/libfreetype.so (0x00411000) libass.so.4 =/usr/local/lib/libass.so.4 (0x0091 a000) 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 =& Gt /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 (0x004e500 0) libvo-aacenc.so.0 =/usr/local/lib/libvo-aacenc.so.0 (0x00799000) libtwolame.so.0 =/usr/local/li b/libtwolame.so.0 (0x0050d000) libtheoraenc.so.1 =/usr/local/lib/libtheoraenc.so.1 (0x0052d000) Libtheo Radec.so.1 =/USR/local/lib/libtheoradec.so.1 (0x00779000) libspeex.so.1 =/usr/local/lib/libspeex.so.1 (0x00c94000) Lib mp3lame.so.0 =/usr/local/lib/libmp3lame.so.0 (0x0088c000) libfaac.so.0 =/usr/local/lib/libfaac.so.0 (0x00 573000)/lib/ld-linux.so.2 (0x005c2000) libdl.so.2 =/lib/libdl.so.2 (0x001a1000) libraw1394.so.1 1 =/usr/local/lib/libraw1394.so.11 (0x005b5000) libfribidi.so.0 =/usr/local/lib/libfribidi.so.0 (0x007b50 XX) 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)
The LD_LIBRARY_PATH environment variable is not set in my system, and the last it compiled FFmpeg runtime relies on a very many dynamic libraries. Now let's move one of the library libmp3lame.so.0 from/usr/loca/lib to the/OPT directory, and execute the ldconfig, and let libmp3lame.so.0 disappear completely from the/etc/ld.so.cache. In fact, libmp3lame.so.0 is just a symbolic link libmp3lame.so.0.0.0, we really need to move the latter, after the end of the execution of ldd/usr/local/bin/ffmpeg when the result is as follows:
[[email protected] ~]# 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 (0X00CCD 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) Lib swresample.so.0 =/usr/local/lib/libswresample.so.0 (0x00b8f000) libswscale.so.2 =/usr/local/lib/libswscal E.so.2 (0x0024a000) libavutil.so.52 =/usr/local/lib/libavutil.so.52 (0x005d7000) libm.so.6 =/lib/l Ibm.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/lib dc1394.so.22 (0x00436000) Librt.so.1 =/lib/librt.so.1 (0x00a06000) libfreetype.so =/usr/local/lib/libfreetype.so (0x0052d0 XX) 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 =&G T /usr/local/lib/librtmp.so.0 (0x004b9000) libz.so.1 =/lib/libz.so.1 (0x0022a000) libx264.so.132 =/U sr/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-AAC enc.so.0 (0x005a8000) libtwolame.so.0 =/usr/local/lib/libtwolame.so.0 (0x006f0000) libtheoraenc.so.1 =& Gt /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//sure as red:) libfaac.s o.0 =/usr/local/lib/libfaac.so.0 (0x004a4000)/lib/ld-linux.so.2 (0x0050d000) libdl.so.2 =/lib/lib Dl.so.2 (0x0023e000) libraw1394.so.11 =/usr/local/lib/libraw1394.so.11 (0x004f6000) libfribidi.so.0 =&G T /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 (0x0080600 0) [[email protected] ~]# ffmpeg--helpffmpeg:error while loading gkfx libraries:libmp3lame.so.0:cannot open Shar Ed object File:no such file or directory//At this time ffmpeg of course not run up
Let's try Ld_library_path and see if it works:
[[email protected] opt]# export ld_library_path=/opt: $LD _library_path[[email protected] Opt]#[[email protected] 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) libswres ample.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.S O.6 (0x00af9000) libpthread.so.0 =/lib/libpthread.so.0 (0x00823000) libc.so.6 =/lib/libc.so.6 (0x0 083e000) 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 (0x00cb300 0) 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/l ibx264.so.132 (0x00f80000) libvorbisenc.so.2 =/usr/local/lib/libvorbisenc.so.2 (0x07c66000) LIBVORBIS.S o.0 =/usr/local/lib/libvorbis.so.0 (0x0041a000) libvo-aacenc.so.0 =/usr/local/lib/libvo-aacenc.so.0 (0x00 76c000) 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/l Ocal/lib/libspeex.so.1 (0x00221000) libmp3lame.so.0 = not found//Nani?!!!! 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)
Remember the above mentioned soft link, libmp3lame.so.0 is libmp3lame.so.0.0.0 's soft link, which is a convention for the naming conventions of dynamic libraries, we just need to/opt/ Setting up a soft link to/opt/libmp3lame.so.0.0.0 named libmp3lame.so.0 in the directory is OK:
[[email protected] opt]# lslibmp3lame.so.0.0.0[[email protected] opt]# ln-s libmp3lame.so.0.0.0 Libmp3lame.so.0[[email protected] opt]# lltotal 316lrwxrwxrwx. 1 root root 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[[email protected] opt]# ldd/usr/local/bin/ffmpeg linux-ga Te.so.1 = (0x00cc4000) libavdevice.so.54 =/usr/local/lib/libavdevice.so.54 (0x00577000) Libavfilte R.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 =/US r/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/libav Util.so.0x005ba000 libm.so.6 =/lib/libm.so.6 (0x00452000) libpthread.so.0 =/lib/libpthread.so.0 (0x00 1c0000) 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) Li Bz.so.1 =/lib/libz.so.1 (0x00599000) libx264.so.132 =/usr/local/lib/libx264.so.132 (0x02bc9000) Li bvorbisenc.so.2 =/usr/local/lib/libvorbisenc.so.2 (0x05ccd000) libvorbis.so.0 =/USR/LOCAL/LIB/LIBVORBIS.S o.0 (0x00640000)libvo-aacenc.so.0 =/usr/local/lib/libvo-aacenc.so.0 (0x00834000) libtwolame.so.0 =/usr/local/lib/libtwola me.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)//finally completed:) libfaac.so.0 =/usr/local/lib/libfaa c.so.0 (0x006e8000)/lib/ld-linux.so.2 (0x003b6000) libdl.so.2 =/lib/libdl.so.2 (0x001f4000) Lib raw1394.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 =/U sr/local/lib/libogg.so.0 (0x001f9000) libexpat.so.1 =/lib/libexpat.so.1 (0x007e3000)
So, for the dynamic library path to find a variety of problems, nothing but so two categories, the key is to find the right reason, the remedy, can charm.
There are so many ways to set the run-time search path for the dynamic library, which have the following precedence:
- Ld_run_path Setting the path
- The path set by the linker using the-rpath or-r option
- Ld_library_path Setting the path
- Path to/etc/ld.so.conf configuration
- /usr/lib/and/lib/
where the Ld_run_path and linker use the-rpath or-r option are all set in the executable file of the library rpath.
Refer to its RELATED links:
Http://blog.chinaunix.net/uid-23069658-id-4028681.html
http://blog.csdn.net/renwotao2009/article/details/51398739
http://blog.csdn.net/hktkfly6/article/details/61922685
Problems of locating paths of dynamic libraries under Linux