Configure,pkg-config and Pkg_config_path

Source: Internet
Author: User
Tags gtk openssl openssl library

1. What is configure

Configure will check the environment on which the program is compiled based on the incoming configuration items and configure the program compilation installation, eventually generating the makefile file required for the compilation to be read by program make and then invoking the relevant compiler (usually invoking the compiler is GCC) To compile the final binary program. The Configure script, when checking for dependent environments (for example, the version of the software being relied on, the corresponding library version, and so on), usually detects the dependent environment through the Pkg-config tool.

2. What is Pkg-config

Pkg-config is used to retrieve information about the installation library files in the system, typically as a compilation and connection to a library. Generally speaking, if the header file of the library is not in the/usr/include directory, then you need to specify its path with the-I parameter at compile time. Because the same library may be located in different directories on different systems, users can also install the library in a different directory, so even with the same library, due to the different path of the library, the path of the header file specified with the-i parameter and the path to specify the Lib library with the-l parameter at connection may be different. The result is that the compiler command interface is not unified. The problem may occur when the same program is copy from one machine to another because of the inconsistency between compilation and connection.
Pkg-config is a tool used to solve the problem of not unifying the interface of compiling connections. Basic idea: Pkg-config is a. pc file that is provided by a library to obtain all the necessary information about the library, including version information, parameters for compiling and connecting, and so on. The required information can be extracted for compilation and connection using the parameters (–cflags,–libs) provided by Pkg-config. This way, no matter where the library file is installed, the. pc file corresponding to the library can be positioned accurately, using the same compilation and connection commands to unify the compilation and connection interfaces. The main functions it provides are:

<1> Check the version number of the library. If the required library version does not meet the requirements, print out an error message to avoid connecting to the wrong version of the library file.
<2> get compilation preprocessing parameters, such as macro definition, path of header file.
<3> get compilation parameters, such as the location of the library and other libraries it relies on, file names, and some other connection parameters.
<4> automatically joins the settings of other libraries on which you depend.

By default, the. pc file for each library that supports Pkg-config is installed in the Lib/pkgconfig directory in the installation directory. The new software will generally install the. pc file, not be able to create it yourself, and set the environment variable Pkg_config_ Path to find. pc file paths, otherwise how to find it. There are two basic prerequisites for using the Pkg-config tool to extract compilation and connection parameters for a library:

The <1> library itself must provide a corresponding. pc file at the time of installation. Library descriptions that do not do this do not support the use of the Pkg-config tool.
<2> Pkg-config must know where to look for this. pc file.

3.pkg_config_path.

The second basic condition above is to set the environment variable. Environment variable Pkg_config_path is used to set the search path for the. pc file, Pkg-config searches in the order of the set path until the specified. pc file is found. In this way, the setting of the search path for the header file of the library actually becomes the setting for the. pc file search path. After installing a library that needs to be used, such as glib, the corresponding. pc files, such as GLIB-2.0.PC, are copied to the/usr/lib/pkgconfig directory, and the second is by setting the environment variable Pkg_config_ Path to add a search path to the glib-2.0.pc file.
After this setting, other programs or libraries that use the GLib library pkg-config know that the first thing to do is to go to the/opt/gtk/lib/pkgconfig directory to find glib-2.0.pc (GTK + and other dependent libraries of. pc files will also be copied here, and will be here first to search for their corresponding. pc files. After that, the compilation and connection parameters of the library can be extracted by Pkg-config for the program to use when compiling and connecting. Also note that this setting of the environment variable is only valid for the current terminal window. If you are in a terminal window that does not have the above settings, Pkg-config will not find the newly installed glib-2.0.pc file, which may cause subsequent installations (such as ATK installed after glib) to fail.
In our installation scenario, because of the setting of GTK + and its dependent libraries using environment variables, when the system restarts or a new terminal window is opened, if you want to use the newly installed GTK + library, you need to reset Pkg_config_path and ld_ as above Library_path environment variables.
This method of using GTK + is one more procedure for setting up a library before using it. Although somewhat cumbersome, it is one of the safest ways to use the GTK + library without any impact on the system's existing programs that use the GTK + library, such as the GNOME desktop.

Action Example:

$pkg-config--modversion GTK + (see version 1.2.x)
$pkg-config--modversion gtk+-2.0 (View 2.x version)
$pkg-config--version (view pkg-config version)

$pkg-config--list-all |grep GTK (see if GTK is installed)
I entered Pkg-config--modversion gtk+-2.0, prompted not to find the xproto.pc file, you need to put the directory containing the file into the Pkg_config_path, a search, the file in the/usr/share/ Pkgconfig, then change the environment variable into:
Export Pkg_config=/usr/local/bin/pkg-config
Export Pkg_config_path=/usr/share/pkgconfig:/usr/lib/pkgconfig
Remember: Two paths are separated by ': ', not ', ', or '; Don't let the big problem be.

Instance 2:linux when compiling source code of open source project, need OpenSSL library,./configure hint said that can not find OpenSSL library package, obviously already installed OpenSSL,:

Workaround:

Export Pkg_config_path=/usr/local/ssl/lib/pkgconfig

Ldconfig

Continue to configure, then OK resolved.



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.