Compile Glib in Linux

Source: Internet
Author: User
Compile Glib in Linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. 1./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 under 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 in/usr/local, but not in/etc/ld. so. add the/usr/local/lib search path to the conf file. Therefore, compiling gtk +-2.4.13 may cause errors. In this case, there are two solutions:

1: when compiling the glib-2.4.x, specify the installation to/usr, so that the library file will be placed in/usr/lib, gtk won't find the required library file. For the installation library file, this is a good way, so you don't need to set PKG_CONFIG_PATH (recommended, should be very convenient)

2: Add/usr/local/lib to/etc/ld. so. in conf, gtk will be searched for/usr/local/lib during installation. You can also find the required library to add/usr/local/lib to/etc/ld. so. conf is also required. In this way, the problem will not occur after you install Dongdong to local. 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:

/Usr/X11R6/lib

/Usr/local/lib

/Opt/lib

Ldconfig is a program. It is usually located under/sbin and used by the root user. Its function is to set/etc/ld. so. the library files in the path listed in conf are cached to/etc/ld. so. cache for use. Therefore, after installing some library files (for example, 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. in the cache, even if the library file is clearly under/usr/lib, it will not be used. Remember to run ldconfig after modifying the library file, you can run it in any directory.

2. PKG_CONFIG_PATH environment variable

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?

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's talk about where it comes out, when the pkgconfig-x.x.x package is installed, there is more pkg-config, it is the need for PKG_CONFIG_PATH. What is pkgconfig-x.x.x?

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

Configure determines whether your software version meets the requirements based on the information. 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 very simple, set the correct PKG_CONFIG_PATH, if the glib-2.x.x is installed under/usr/local/, then the glib-2.0.pc will be under/usr/local/lib/pkgconfig, add this path to PKG_CONFIG_PATH.

Set:

1. Open the profile file through vi/etc/profile

2. Add the following statement at the end of the profile file:

Export PKG_CONFIG_PATH = $ PKG_CONFIG_PATH:/usr/local/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 will search for/usr/lib by default, which saves a lot of trouble. However, from the source package management perspective, it is a problem to manage all packages under/usr, it is better to install it in/usr/local for convenient management. In fact, you only need to set the ld. so. conf and PKG_CONFIG_PATH paths, and then OK.
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.