How does one manage shared libraries (*. So) during Linux running? In Linux, the search and loading of shared libraries are implemented by/lib/lD. So. LD. So searches for the shared libraries used by applications in the standard channels (/lib,/usr/lib.
However, how can lD. So find the shared library that needs to be used in non-standard channels?
Currently, a common practice in Linux is to add non-standard channels to/etc/lD. So. conf and run ldconfig to generate/etc/lD. So. cache. When ld. So is loaded to the shared library, it will be searched from LD. So. cache.
In general, Linux's predecessor UNIX also has an environment variable-LD_LIBRARY_PATH to handle non-standard channels of shared libraries. When ld. So loads the shared library, it will also find the path set by this variable. However, there are many claims that LD_LIBRARY_PATH variables should be avoided, especially as global variables. These sounds are:
* LD_LIBRARY_PATH is not the answer-http://prefetch.net/articles/linkers.badldlibrary.html
* Why LD_LIBRARY_PATH is bad-http://xahlee.org/UnixResource_dir/_/ldpath.html
* LD_LIBRARY_PATH-just say no-http://blogs.sun.com/rie/date/20040710
Another way to solve this problem is to specify the run-time path through the-r <path> option during compilation.
1. add something to/lib and/usr/lib without modifying/etc/lD. so. conf, but after the execution, you need to call ldconfig. Otherwise, this library will not be found.
2. When you want to add something out of the above two directories, you must modify/etc/lD. So. conf and then call ldconfig. Otherwise, you will not be able to find it.
For example, if you have installed a MySQL file to/usr/local/MySQL, MySQL has a lot of Libraries under/usr/local/MySQL/lib. In this case, you need to go to/etc/lD. so. add a/usr/local/MySQL/lib line under the conf file and save it. After ldconfig is saved, the new library can be found when the program is running.
3. If you want to put lib outside these two directories, but you do not want to add anything in/etc/lD. So. conf (or you do not have the permission to add anything ). That is, the global variable LD_LIBRARY_PATH export will be used to find the library in the directory when running the program. Generally, this is only a temporary solution that can be used when you do not have the permission or need it temporarily.
4. ldconfig is related to running the program and has nothing to do with compiling. During compilation, you should add-L instead of obfuscation.
5. In short, it is recommended that you perform ldconfig for any changes to the library. Otherwise, unexpected results may occur. It won't take too much time, but it will save a lot of time.
Http://hi.baidu.com/fanzier/blog/item/222ba3ec74cb9a2463d09fb5.html
LD_LIBRARY_PATH is the environment variable that everyone is most familiar with. It tells loader which directories can find shared libraries. You can set multiple search directories separated by colons. In Linux, another method is provided to accomplish the same function. You can add these directories to/etc/lD. so. conf, or in/etc/lD. so. conf. d. Create a file and add the directory to the file. Of course, this is globally effective within the system scope, while environment variables are only valid for the current shell. By convention, unless you specify in the above method, the loader will not find the shared library in the current directory, just as the shell will not find the executable file currently.
Original address http://hi.baidu.com/cooltown/blog/item/d038a945d1a6be3887947314.html
Article Source: DIY tribe (http://www.diybl.com/course/6_system/linux/Linuxjs/20090314/161447.html)