/Etc/lD. So. conf and ldconfig, pkg_config_path

Source: Internet
Author: User
Tags gtk

Now we know the dynamic and static function libraries, and we know that most of the current Linux systems make the function libraries into dynamic function libraries. Next we will discuss how to increase the function library reading performance. We know that the access speed of the memory is several times that of the hard disk. Therefore, if you load common dynamic function libraries into the memory (high-speed cache, cache ), when the software kit uses a dynamic function library, it does not need to be read from the hard disk again, which can improve the reading speed of the dynamic function library. In this case, ldconfig and/etc/lD. So. conf are required.

The process of loading a dynamic function library to a cache is as follows:

1. First, write "the directory where the dynamic function library in the cache is located" in/etc/lD. So. conf. Note that it is a directory rather than a file.

2. Use the ldconfig execution file to read/etc/lD. So. conf data into the cache.

3. Record Data in the/etc/lD. So. cache file at the same time.

In fact, ldconfig can also be used to determine the connection information of the dynamic function library. Use Fedora Core 4 for testing. Suppose you want to add the MySQL function library to the cache:

[Root @ Linux ~] # Ldconfig [-F conf] [-C cache] [-p]

Parameters:

-F conf: conf indicates the name of a file, that is, use conf as libarary

Path obtained from the function library, instead of using/etc/lD. So. conf as the default value

-C cache: cache refers to the name of a file, that is, cache is used as a cache for temporary storage.

Function library information, without/etc/lD. So. cache as the default value

-P: Lists All data in the current function library (data in/etc/lD. So. cache ).

Example:

 

Example 1: assume that the MySQL database function library is in/usr/lib/MySQL, how does one read the cache?

[Root @ Linux ~] # Vi/etc/lD. So. conf

Include lD. So. conf. d/*. conf

/Usr/lib/MySQL <= This line is added.

 

[Root @ Linux ~] # Ldconfig

# No information is displayed on the screen. It is normal.

 

[Root @ Linux ~] # Ldconfig-P

928 libs found in cache '/etc/lD. So. cache'

Libz. so.1 (libc6) =>/usr/lib/libz. so.1

Libz. So (libc6) =>/usr/lib/libz. So

... Omitted in the middle ......

Through the above operation, we can read mysql-related function libraries into the high-speed cache, which can speed up reading the function library. Sometimes you may add some dynamic function libraries installed by tarball. When you want to allow connections to these dynamic function libraries to be read into the cache, you can write the Directory Name of the dynamic function library to/etc/lD. so. conf, and then execute ldconfig.

 

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////

 

First, describe/etc/lD. So. conf:

This file records the path of the dynamic link library used during compilation.
By default, the compiler only uses the library files in the/lib and/usr/lib directories.
If you have installed some libraries, for example, when installing GTK +-2.4.13, it will require glib-2.0> = 2.4.0.
-- Prefix =/usr is not specified, so the glib library is installed under/usr/local, and/usr/local/lib is not added to/etc/lD. So. conf.
This search path causes an error when compiling GTK +-2.4.13.
There are two solutions to this problem:
A: When compiling the glib-2.4.x, specify the installation to/usr, so that the library file will be placed in/usr/lib, GTK will not find the required Library File
This is a good method for installing the library file, so you do not need to set pkg_config_path (described later)

2. Add/usr/local/lib to/etc/lD. so. conf. Then, when installing GTK, you will search for/usr/local/lib and find the required library.
Adding/usr/local/lib to/etc/lD. So. conf is also required. In this way, the problem will not occur when you install Dongdong to local.
It is wise to add the paths that may store the 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:
/Usr/x11r6/lib
/Usr/local/lib
/Opt/lib

Let's take a look at what ldconfig is like:

It is a program, usually located under/sbin, which is used by the root user. The specific functions and usage can be found in man ldconfig.
To put it simply, it 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. conf to add a new library path, run/sbin/ldconfig
Make all the library files cached in LD. So. cache. If it is not done, it will not be used even if the library file is clearly under/usr/lib.
During the compilation process, I encountered an error and lacked the xxx library. I found that the library was clearly there. I wanted to yell at computer pig. Pai_^
I once made this mistake when compiling KDE (it needs to be run once every compilation of a good stuff), so

Remember to run ldconfig after modifying the library file, and run it in any directory.

Let's talk about the variable pkg_config_path:

I often see someone asking on the Forum, "Why have I installed the glib-2.4.x, But compiling GTK +-2.4.x still prompts that the glib version is too low?
Why did I install the glib-2.4.x, or did I prompt that a?... could not be found ?...... "It's all about this variable.
First, let's take a look at the errors that occur during the compilation process (compile GTK +-2.4.13 ):

Checking for PKG-config.../usr/bin/PKG-config
Checking for glib-2.0> = 2.4.0 ATK> = 1.0.1 pango> = 1.4.0... package glib-2.0 was not found in the PKG-config search path.
Perhaps you shoshould Add the directory containing 'glib-2.0.pc'
To the pkg_config_path environment variable
No package 'glib-2.0 'Found

Configure: Error: library requirements (glib-2.0> = 2.4.0 ATK> = 1.0.1 pango> = 1.4.0) not met; consider adjusting the pkg_config_path environment variable if your libraries are in a nonstandard prefix so PKG-config can find them.
[Root @ newlfs GTK +-2.4.13] #
Obviously, the above section shows that no glib-2.4.x is found and prompts that the glib-2.0.pc should be added to pkg_config_path.
What exactly is this PKG-config pkg_config_path glib-2.0.pc doing? Let me tell you have _^
First talk about where it came out, when the installation of the pkgconfig-x.x.x package, it is more PKG-config, it is the need for pkg_config_path stuff
What is pkgconfig-x.x.x? Here is a description:

The pkgconfig package contains tools for passing the include path and/or library paths to build tools during the make File Execution.

PKG-config is a function that returns meta information for the specified library.

The default setting for pkg_config_path is/usr/lib/pkgconfig because of the prefix we use to install pkgconfig. you may add to pkg_config_path by exporting additional paths on your system where pkgconfig files are installed. note that pkg_config_path is only needed when compiling packages, not during Run-Time.

After reading this instruction, you probably know what it is.
In fact, PKG-config is a program that provides system information to the configure program, such as the software version, library version, library path, and so on.
This information is only used during compilation. You can see a lot of *. PC under ls/usr/lib/pkgconfig and open it in a text editor.
You will find information similar to the following:

Prefix =/usr
Exec_prefix = $
Libdir = $/lib
Includedir = $/include

Glib_gen1_al = glib-gen1_al
Gobject_query = gobject-Query
Glib_mkenums = glib-mkenums

Name: glib
Description: C utility Library
Version: 2.4.7
Libs:-L $-lglib-2.0
Cflags:-I $/glib-2.0-I $/glib-2.0/include

See, configure depends on the information to determine whether your software version meets the requirements. And get the location where these things are located, or where to find them.
I don't need to say that you also know why the above problems have occurred.

The solution is simple, set the correct pkg_config_path, if the glib-2.x.x is mounted to/usr/local/, then the glib-2.0.pc will
Under/usr/local/lib/pkgconfig, add this path to pkg_config_path. And make sure that configure finds the correct
Glib-2.0.pc, is to take the other lib/pkgconfig directory glib-2.0.pc is killed. (If yes, ^-^)
After setting, you can add it ~ /. Bashrc, for example:
Pkg_config_path =/opt/kde-3.3.0/lib/pkgconfig:/usr/local/pkgconfig:
/Usr/x11r6/lib/pkgconfig
[Root @ newlfs ~] # Echo $ pkg_config_path
/Opt/kde-3.3.0/lib/pkgconfig:/usr/local/pkgconfig:/usr/x11r6/lib/pkgconfig

It can be seen from the above that it is very good to specify the installation to/usr when installing the library file, whether it is/etc/lD. So. conf or pkg_config_path
By default,/usr/lib is searched, which saves a lot of trouble. However, in terms of source code package management
Management is a problem. It is better to install it in/usr/local for convenient management.
In fact, after you set the lD. So. conf and pkg_config_path paths, it will be OK. ^_^

Appendix: ldconfig man (8)

Name
/Sbin/ldconfig-configure dynamic linker Run Time Bindings

Synopsis
/Sbin/ldconfig [-nnvxv] [-F conf] [-C cache] [-r root] Directory...
/Sbin/ldconfig-L [-v] library...
/Sbin/ldconfig-P

Description

Ldconfig creates the necessary links and cache to the most recent shared libraries found in the Directories specified on the command line, in the file/etc/lD. so. conf, and in the trusted directories (/lib and/usr/lib ). the cache is used by the run-time linker, LD. so or ld-linux.so. ldconfig checks the header and filenames of the libraries it encounters when determining which versions shoshould have their links updated.

Ldconfig will attempt to deduce the type of ELF libs (ie. libc5 or libc6/glibc) based on what C libs, if any, the Library was linked against. therefore, when making dynamic libraries, it is wise to explicitly link against libc (use-LC ).

Some existing libs do not contain enough information to allow the deduction of their type. therefore, the/etc/lD. so. CONF file format allows the specification of an expected type. this is only used for those elf libs which we can not work out. the format is "dirname = type", where type can be libc4, libc5, or libc6. (this syntax also works on the command line .) spaces are not allowed. also see the-P option. ldconfig shocould normally be run by the superuser as it may require write permission on some root owned directories and files.

Options
-V
Verbose mode. Print current version number, the name of each directory as it is scanned, and any links that are created. Overrides quiet mode.

-N

Only process Directories specified on the command line. don't process the trusted directories (/lib and/usr/lib) nor those specified in/etc/lD. so. conf. implies-n.

-N

Don't rebuild the cache. Unless-X is also specified, links are still updated.

-X

Don't update links. Unless-N is also specified, the cache is still rebuilt.

-F Conf
Use conf instead of/etc/lD. So. conf.
-C Cache
Use cache instead of/etc/lD. So. cache.
-R Root
Change to and use root as the root directory.
-L
Library mode. Manually link individual libraries. intended for use by experts only.

-P

Print the lists of directories and candidate libraries stored in the current cache.

Files
/Lib/lD. So
Run-time linker/loader

/Etc/lD. So. conf

File containing a list of colon, space, tab, newline, or comma-separated directories in which to search for libraries.

/Etc/lD. So. Cache

 

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.