Linux Shared Library: LD_LIBRARY_PATH and ld. so. conf

Source: Internet
Author: User


LD_LIBRARY_PATH Linux environment variable name. This environment variable is mainly used to specify other paths except the default path for finding a shared library (dynamic link library. (This path is located before the default path)
Some specific dynamic libraries are often used when Porting Programs, and these compiled dynamic libraries are placed in our own directories. In this case, you can set these directories to LD_LIBRARY_PATH. When the execution function is dynamically linked. so, if the file is not in the '/usr/local/lib' and'/usr/lib' directory by default '. for www.2cto.com, You need to specify the environment variable LD_LIBRARY_PATH. If you need to add a new path name to an existing environment variable, use the following method: LD_LIBRARY_PATH = NEWDIRS: $ LD_LIBRARY_PATH. (newdirs is a new path string) How to manage shared libraries (*. so? 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. Traditionally, Linux's predecessor Unix also has an environment variable: LD_LIBRARY_PATH to handle shared libraries with non-standard channels. When ld. so loads the shared library, it will also find the path set by this variable. LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:./libexport LD_LIBRARY_PATH
However, there are many claims that LD_LIBRARY_PATH variables should be avoided, especially as global variables. These sounds: * LD_LIBRARY_PATH is not the answer-http://prefetch.net/articles/linkers.badldlibrary.html* Why LD_LIBRARY_PATH is bad-character 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. Www.2cto.com 1. add something to/lib and/usr/lib without modifying/etc/ld. so. conf, but after it is finished, you need to call ldconfig. Otherwise, this library will not find 2. you must modify/etc/ld when you want to add something out of the preceding two directories. so. conf, and then call ldconfig. Otherwise, a mysql to/usr/local/mysql is installed. mysql has a lot of Libraries under/usr/local/mysql/lib, in this case, the/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. The environment variable www.2cto.com LD_LIBRARY_PATH is the most familiar to everyone. 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 and then call ldconfig. 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. There are many methods to determine the library search path. LD_LIBRARY_PATH is only one of them. For example, compile the rpath parameter of the command line. The LD_RUN_PATH environment variable during connection. /Lib,/usr/lib standard directory. Dynamic connector Cache/etc/ld. so. conf. Author cjw.zs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.