About adding a shared library path to Ubuntu

Source: Internet
Author: User
About adding a shared library path to Ubuntu: 1. Write the absolute path to/etc/ld. so. conf2.ldconfigOK! * **************************** The following is a tedious explanation, if you want to see it, just look at it ..... Library files are used when they are connected (static databases and shared libraries) and run (only programs that use shared libraries). Their search paths are set in the system. In Linux,/lib and/usr/lib

To add a shared library path to Ubuntu:

1. Write the absolute path to/etc/ld. so. conf.

2. ldconfig



The following is a tedious explanation. If you are willing to read it, just take a look at it .....

Library files are used when they are connected (static databases and shared libraries) and run (only programs that use shared libraries). Their search paths are set in the system. In Linux, the/lib and/usr/lib directories are used as the default library search paths. Therefore, you can directly use these directories without setting the search path. For libraries outside the default library search path, you need to add the location of the database to the library search path. You can use either of the following methods to set the search path for a library file:

Specify the library search path in the environment variable LD_LIBRARY_PATH.

Add the library search path to the/etc/ld. so. conf file.

It is wise to add the paths that may store library files to/etc/ld. so. conf.

The addition method is extremely simple. It is okay to directly write the absolute path of the library file into it, one line at a time. For example:




Note that the second search path setting method is sufficient for locating the Library (including the shared library and static library) when the program is connected, however, the execution of programs that use the shared library is insufficient. This is because in order to speed up the positioning of the shared library during program execution and avoid the inefficiency of searching for the shared library using the search path, it is to directly read the/etc/ld LIBRARY list file. so. from the cache. /Etc/ld. so. cache is a non-text data file and cannot be edited directly. It is based on/etc/ld. so. the search path set in conf is generated by the/sbin/ldconfig command to centralize the shared library files in these search paths (the ldconfig command must be executed with the root permission ). Therefore, in order to ensure the library location during program execution, in/etc/ld. so. after setting the library search path in conf, you must also run the/sbin/ldconfig command to update/etc/ld. so. cache file. Ldconfig, to put it simply, caches the library files in the paths listed in/etc/ld. so. conf to/etc/ld. so. cache for use. Therefore, after installing some library files (such as just installed glib), or modifying ld. so. after adding a new library path to the conf file, run/sbin/ldconfig to cache all the library files to the ld. so. cache, if not done, even if the library file is clearly under/usr/lib, it will not be used. The result is wrong during compilation, and the xxx library is missing, check and find that the computer is clearly there, and you want to scold the computer.

When a program is connected, you can specify the search path of the library file (static library and shared library) In addition to the preceding settings. You can also use the-L parameter to explicitly specify the search path. Because the path set with-L is preferentially searched, the path of the database to be connected is usually specified in this way.

As mentioned above, there are two ways to set the library search path: In the environment variable LD_LIBRARY_PATH and in the/etc/ld. so. conf file. The second setting method requires the root permission to change the/etc/ld. so. conf file and execute the/sbin/ldconfig command. In addition, after the system is restarted, all GTK2-based programs will use the newly installed GTK library at runtime. Unfortunately, due to changes in the GTK version, this may sometimes cause compatibility problems for applications and cause some program running to be abnormal. To avoid the above situations, the first method is used to set the search path of the library during installation of GTK and its dependent libraries. This setting method does not require the root permission and is easy to set:

$ Export LD_LIBRARY_PATH =/opt/gtk/lib: $ LD_LIBRARY_PATH

Run the following command to view the setting content of LD_LIBRAY_PATH:


Now, the two settings of the database are complete.

Related Article

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.