Summary: Configure, PKG-config, and pkg_config_path

Source: Internet
Author: User
Tags gtk

I think everyone has installed software with the source code in Linux. What is the first step to install software with the source code? Download the source code. That's right, Mr. Wang. You are too talented ..

The real first step is./configure. Yes, so I have also seen the relationship between PKG-config and pkg_config_path. This is the topic of today.

1. What is configure?

Configure checks the environment on which the program is compiled and installed based on the input configuration items, generate the MAKEFILE file required for compilation for the program make to read and use, and then call the relevant Compilation Program (usually calling the Compilation Program is GCC) to compile the final binary program. When the configure script checks the corresponding dependent environment (for example, the software version and the corresponding library version), it usually uses the PKG-config tool to detect the corresponding dependent environment.

2. What is PKG-config?

PKG-config is used to retrieve information about installed library files in the system. It is typically used for library compilation and connection. Generally, if the header file of the library is not in the/usr/include directory, you must use the-I parameter to specify the path during compilation. Because the same library may be located in different directories on different systems, users can install the library in different directories during library installation, even if the same library is used, because of the different library paths, the path of the header file specified by the-I parameter may be different from the path of the Lib library specified by the-l parameter during connection, the result is that the compilation command interface is inconsistent. The compilation and connection inconsistency may cause problems when the same program is copied from one machine to another.
PKG-config is a tool used to solve the problem of inconsistent compiling connection interfaces. Basic Idea: PKG-config is A. PC file provided by the database to obtain various necessary information about the database, including version information, parameters required for compilation and connection. When needed, you can use the parameters (-cflags,-libs) provided by PKG-config to extract the required information for compilation and connection. In this way, no matter where the library file is installed, the. PC file corresponding to the Library can be accurately located, and the same compilation and connection commands can be used to unify the compilation and connection interfaces. It provides the following functions:

<1> check the database version number. If the required library version does not meet the requirements, print the error message to avoid connecting to the library file of the wrong version.
<2> obtain the compilation preprocessing parameters, such as macro definition and header file path.
<3> obtain compilation parameters, such as the location of the database and other dependent libraries, file names, and other connection parameters.
<4> automatically add the settings of other dependent libraries.

By default, each library that supports PKG-config corresponds. after installation, the PC files are all located in the LIB/pkgconfig directory in the installation directory. new software is usually installed. PC file. You cannot create it yourself and set the environment variable pkg_config_path to search for it. PC file path. Otherwise, how can this problem be found. There are two basic prerequisites for extracting library compilation and connection parameters using the PKG-config tool:

<1> the library itself must provide a corresponding. PC file during installation. The library description does not support the use of the PKG-config tool.
<2> PKG-config must know where to find the. PC file.

3. pkg_config_path.

The second basic condition above is to set this environment variable. The environment variable pkg_config_path is used to set the search path for the. PC file. PKG-config searches by path until the specified. PC file is found. In this way, the search path of the header file of the library is actually changed to the search path setting for the. PC file. After installing a required library, such as glib. PC files, such as glib-2.0.pc copies to the/usr/lib/pkgconfig directory, the second is to add the search path for the glib-2.0.pc file by setting the environment variable pkg_config_path.
After this setting, when using other programs or libraries of the glib library, PKG-config knows to first find the glib-2.0.pc in the/opt/GTK/lib/pkgconfig directory (GTK + and other. PC files will also be copied here, and the corresponding files will be searched here first. PC files ). Then, you can use PKG-config to extract the library compilation and connection parameters for the program to compile and connect. Note that this setting method of environment variables is only valid for the current terminal window. If there is a terminal window without the above settings, PKG-config will not find the newly installed glib-2.0.pc file, which may cause subsequent installation (such as installation of ATK after Glib) unable to proceed.
In our installation scheme, environment variables are used to set GTK + and its dependent libraries. Therefore, when the system restarts or a new terminal window is opened, to use the newly installed GTK + library, you need to reset the pkg_config_path and LD_LIBRARY_PATH environment variables as above.

Before using GTK +, you need to set the library. Although it seems a little complicated, it is the safest way to use the GTK + Library, and does not use the GTK + library programs (such as GNOME Desktop) that already exist on the system) brings any impact.

Green Channel: Please follow my favorites to contact me

«
Previous Article: Linux Kernel Analysis notes-Virtual File System (II)

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.