Makefile ASSISTANT: pkgconfig

Source: Internet
Author: User
Tags gtk
Have you developed software in UNIX? After writing a program, the compilation runs completely normally and works well on your local machine. You can put it in the source code management system. Then, tell your colleagues that you can use it. At this moment, you have a long breath, a few days of work is not in vain, how fresh air ah, you began to float.

"Hi, how can I not compile it? "You are still immersed in that wonderful feeling, and your arms are full of strength, it seems that there is no problem to beat you. At this point, the idiot has shouted at you.

"No, I am doing well! "On the surface, you are very polite. In fact, you have already opened your mind. It's so stupid that you don't know how to use your mind. Maybe you're right. Last time, he made a simple mistake. Didn't you solve it as soon as you went.

Three times after he shouted, you had to let go of your work. The wonderful feeling just now has vanished without a trace. If it weren't for you to control your mood well, it's time for him to get angry. You enter make in front of your computer and press ENTER elegantly. How can an error be reported? You are confident. However, the results on the screen are somewhat blushing. Damn it, how can libxxx. So not be made?

You can search for libxxx. So in the/usr directory, and everything can't escape your eyes. Strange: How is libxxx. So stored in/usr/local/lib, not in/usr/lib? You can install it in the/lib directory next time.

The above scenario is not a fiction. I have already experienced it several times. It is clear that it is good on the local machine and cannot be compiled on other machines. The operating systems of the two users may be the same, and the required libraries must be installed in different directories due to their personal preferences. In this case, every time I had a hard time, I had to worry about whether I could work in other places.

The pkgconfig we will introduce today provides a beautiful solution to solve the above problems. From then on, you no longer have to worry about it. Pkgconfig provides the following functions:

1.
Check the database version number. If the required library version does not meet the requirements, it prints an error message to avoid link to the library file of the wrong version.
2. Obtain the pre-compilation parameters, such as macro definition and header file location.
3.
Obtain the link parameters, such as the location of the Library and other dependent libraries, file names, and other connection parameters.
4. automatically add the settings of other dependent libraries.

All of this is automatic. It doesn't matter where the library file is installed!

Before using pkgconfig, let's talk about the principles of pkgconfig. pkgconfig is not an Genie and you can get the above information out of thin air. In fact, to allow pkgconfig to obtain this information, the database provider must provide a. PC file. For example, the content of a PC file in GTK +-2.0 is as follows:

Prefix =/usr
Exec_prefix =/usr
Libdir =/usr/lib
Includedir =/usr/include
Target = X11

Gtk_binary_version = 2.4.0
Gtk_host = i386-redhat-linux-gnu

Name: GTK +
Description: gimp Tool Kit ($ {target} target)
Version: 2.6.7
Requires: gdk-$ {target}-2.0 ATK
Libs:-L $ {libdir}-lgtk-$ {target}-2.0
Cflags:-I ${includedir}/gtk-2.0

This file is usually stored in/usr/lib/pkgconfig/or/usr/local/lib/pkgconfig/. Of course, it can be stored anywhere else, for example, the PC files related to X11 are stored in/usr/x11r6/lib/pkgconfig. In order for pkgconfig to find your PC file, you need to set the path of the PC file in the environment variable pkg_config_path.

The usage is very simple. For example, we need to compile a program using the GTK + Library:
Gcc-G arrow. C-o arrow 'pkg-config "GTK +-2.0> 2.0.0" -- cflags -- libs'

As long as GTK + 2.0 is installed, compilation is normal no matter where it is installed. Is this much simpler?

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.