pkg-config usage

pkg-config usage

pkg-config

pkg-config program is used to do? Simply put, the program is to provide information to the user library path to the program, version number, and so on.
For example say we run the following command:
pkg-config to view the parameters of gcc CFLAGS
$pkg-config --libs --cflags opencv
Following information is displayed:
-I/usr/include/opencv -lcxcore -lcv -lhighgui -lcvaux
Tell me what you see is not that we CFLAGS when using gcc compiler connection parameters it?
So when we need to compile a database connection, we just need to line above parameters which can be added to gcc.
It also configure the role, it will check packages you need to generate the appropriate information.
That pkg-config know from where these information? It is from a package called xxx.pc find this file. Take the example above that it is from this document check opencv.pc known.
That pkg-config  , how will know opencv.pc this document?
Here we look at pkg-config how it works.
By default, the pkgconfig first looks for related packets (eg OpenCV) corresponding to a respective file (opencv.pc) in the prefix / lib / pkgconfig / in. Linux on the route named / usr / lib / pkconfig /. If not found, it will be the next PKG_CONFIG_PATH this environment variable to find the path specified. If not found, it will error, such as:
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

Set the environment variable PKG_CONFIG_PATH way of example as follows:
PKG_CONFIG_PATH = Export / CV / lib: $ PKG_CONFIG_PATH

======================================== ========================
view the contents of a .pc file:
[root @ YX pkgconfig] # CAT-2.0.pc the GLib 
prefix = / usr
exec_prefix = / usr
libdir = / lib
includedir = / usr / the include
configexecincludedir = / usr / lib / GLib-2.0 / the include

glib_genmarshal = GLib-genmarshal
gobject_query = GObject-Query
glib_mkenums = GLib-mkenums

the Name: the GLib
the Description: C Utility Library
Version: 2.12.3
Libs: $ {libdir} -L--lglib 2.0  
CFLAGS: includedir -I $ {$ {} -I /glib-2.0 configexecincludedir}

[@ YX the pkgconfig the root] # pwd
/ usr / lib / the pkgconfig

visible .pc file is a library file path thereof, header file path, version number, and other parameters CFLAGS encapsulated.

The first look at a program in the Gtk + `pkg-config --cflags --libs gtk + -2.0` meaning: 
` pkg-config --cflags --libs gtk + -2.0` is pkg-config from the path / usr / lib / the pkgconfig
/gtk+-2.0.pc extracted from the compiled for use.
[YX the pkgconfig the root @] + # CAT GTK -2.0.pc 
prefix = / usr
exec_prefix = / usr
libdir = / usr / lib
includedir = / usr / the include
target = X11

gtk_binary_version = 2.10.0
gtk_host = i686-RedHat Linux-GNU-

name: the GTK +
the Description: the GIMP Tool Kit ($ {target} target)
Version: 2.10.4
the Requires: GDK - $ {target} -2.0 ATK Cairo
Libs: $ {libdir} -L -lgtk - $ {target} -2.0 
CFLAGS : -I $ {includedir} /gtk-2.0 

obviously, can themselves be specified in the: -L / usr / lib -lgtk- { target} -2.0 -I / usr / include / gtk-2.0
below {target look } this is how:

[@ YX the root lib] # LS gt
gThumb / GTK-2.0 / gtkhtml /       
GTK / GTK-Sharp-2.0 / 2.4-the gtkmm /     

[the root @ YX lib] GTK-LS # 2.0 /
2.10.0 2.4.0 immodules the include modules

[@ YX the root lib] GTK-Sharp-LS # 2.0 /
gconfsharp-schemagen.exe

[@ YX the root lib] # pwd
/ usr / lib
so that -lgtk- {target} -2.0 in the {target} null character :  
-lgtk- {target} -2.0 ====> - lgtk - 2.0

At Last So :( substantially theory :)
-L / usr / lib -lgtk- {target} -2.0 -I / usr / the include / ==== 2.0-GTK>
-L / usr / lib -lgtk - 2.0 -I / usr / the include / GTK-2.0
fact some more:
Comparative pkg-config gtk + -2.0 to look at the actual results:
[yuxu @yx base] $ pkg-config --cflags --libs gtk + -2.0
-I/usr/include/gtk-2.0  -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12  -L/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0  
后面还有很多的路径哦。




gtk_base.c:
#include <gtk/gtk.h>
int main(int argc,char *argv[])
{
    GtkWidget  *window;
    gtk_init(&argc,&argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_show(window);
    gtk_main();
    return FALSE;
}

gcc   -o     gtk_base      gtk_base.c    `pkg-config   --cflags   --libs  gtk+-2.0`

Guess you like

Origin www.cnblogs.com/qfmduke/p/10955841.html