LD_LIBRARY_PATH and ld. so. conf, ld_library_path

Source: Internet
Author: User

LD_LIBRARY_PATH and ld. so. conf, ld_library_path

I have previously written an article about the relationship between LD_LIBRARY_PATH and gcc/g ++-L, so I used CPACK to create a Debian installation package, and then on/home /. in bashrc, export LD_LIBRARY_PATH =/usr/loca/lib: $ LD_LIBRARY_PATH is added. Then, the boss told me that this method is not feasible. After some searching, he finally found --- ld. so. conf can solve this problem perfectly.

 

First, why is LD_LIBRARY_PATH not working? Let's see what foreigners say.

Generally, LD is used in the following scenarios:

  • Test the shared library before replacing it.
  • Similarly, a program after upgrade may depend on some dynamic link libraries. If you replace a link library, the program may not work. At this time, you can use LD_LIBRARY_PATH to point to a directory with backup, and then you can replace the system version with no scruples. If an error occurs, copy it back.

It seems that LD_LIBRARY_PATH is used temporarily. Why? Because LD_LIBRARY_PATH is set to global, if it is damaged, it will cause large-scale damage. Don't say this variable won't be changed, but this is an improper way. You can find many articles about LD_LIBRARY_PATH on the Internet. I will not talk more here.

 

However, what should we do if LD_LIBRARY_PATH is not used?

We have already figured out a solution for the Linux system. We will use ld. so. conf to solve this problem. We already know that when linux loads a dynamic library, it will go to the standard path (/lib,/usr/lib) to find the dynamic library used by the application. But we have installed the lib library for our non-standard paths. For example, I have installed my library to/usr/local/lib. What should we do?

 

In Linux, add non-standard channels to/etc/ld. so. conf and run ldconfig to generate ld. so. cache. When Linux loads a shared library, it searches for it from ld. so. cache. [Ldconfig needs to be executed with the root permission]

Therefore, we have installed the library, but after compiling the program, ldd finds that the library cannot be connected, so we need to check whether the library you installed is a non-standard path, if yes, add your non-standard path to/etc/ld. so. in the conf file, and then call ldconfig to generate the ld. so. cache. To check whether your library is already in ld. so. cache, you can use ldconfig-p | grep lib.

 

For Ubuntu, It is also different from other LINUX systems, in/etc/ld. so. conf contains only one include/etc/ld. so. conf. d /*. conf, that is, it cannot be in/etc/ld. so. conf, but we can add it in/etc/ld. so. conf. d. Create a New *. conf adds your non-standard path here. Remember to call sudo ldconfig to generate ld. so. the cache file is enough.

 


What is LD_LIBRARY_PATH?

Linux environment variable name. This environment variable is mainly used to specify a path other than 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 function is dynamically linked to. so, if this file is not in the default directory '/usr/local/lib' and'/usr/lib '.
You must specify the environment variable LD_LIBRARY_PATH.
If you want to add a new path name to an existing environment variable, use the following method:
LD_LIBRARY_PATH = NEWDIRS: $ LD_LIBRARY_PATH. (newdirs is the new path string)
(Note: The GNU system can automatically add environment variables in the/etc/ld. so. conf file)
Setting Method
In linux, you can use the export command to set this value, for example
On the linux terminal, enter: export LD_LIBRARY_PATH =/opt/au1200_rm/build_tools/bin: $ LD_LIBRARY_PATH:
Then enter: export
It will show whether the settings are correct
The export method fails after restart, so you can use vim/etc/bashrc to modify the LD_LIBRARY_PATH variable.
For example, LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/opt/au1200_rm/build_tools/bin.

Why is the ld_library_path setting invalid in ACE?

You can use/etc/ld. so. conf to set the dynamic link library location.
 

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.