[vc_row][vc_column width=”1/1″][vc_column_text]What PKG – config program is used for? Simply put, the program provide the appropriate library path to the users, it also can provide the version number and other information.
For example, we run the following command:
pkg-config parameters to see the gcc CFLAGS parameter
$pkg-config –libs –cflags opencv
Will display the following information:
-I/usr/include/opencv -lcxcore -lcv -lhighgui -lcvaux
Isn’t that the CFLAGS parameter when using and compiling gcc ?
So when we need to build a connection to a database, we just need to add the above line of gcc parameter.
This is the configure’s role, it can check your needed bag,generate the appropriate information.
which file did the pkg-config get the information from ? It is from a package called xxx.pc file. Take the example above that,It get the information from opencv.pc.
How did pkg-config know opencv.pc file?
We can see how pkg-config works as following.
By default, pkg-config first find related packages (such as opencv) corresponding to the appropriate file (opencv.pc) in prefix / lib / pkgconfig / in.On the route named linux / usr / lib / pkconfig /. If not found, it may be in PKG_CONFIG_PATH.If not found, it will be wrong, such as:
Package opencv was not found in the pkg-configsearch 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 methods for example as follows:
export PKG_CONFIG_PATH = / cv / lib: $ PKG_CONFIG_PATH
================================================================
View a pc file content:
[root@yx pkgconfig]# cat glib-2.0.pc
prefix=/usr
exec_prefix=/usr
libdir=/lib
includedir=/usr/include
configexecincludedir=/usr/lib/glib-2.0/include
glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums
Name: GLib
Description: C Utility Library
Version: 2.12.3
Libs: -L${libdir} -lglib-2.0
Cflags: -I${includedir}/glib-2.0 -I${configexecincludedir}
[root@yx pkgconfig]# pwd
/usr/lib/pkgconfig
Visible. Pc file is on its path of library files, header files path, version number, Cflags package and some other parameters.
Let’s look at the first Gtk + program of `pkg-config-cflags-libs gtk + -2.0` mean: :
`Pkg-config-cflags-libs gtk + -2.0` is pkg-config from the path / usr / lib / pkgconfig
/ Gtk +-2.0.pc extracted from used for compilation.
[root@yx pkgconfig]# cat gtk+-2.0.pc
prefix=/usr
exec_prefix=/usr
libdir=/usr/lib
includedir=/usr/include
target=x11
gtk_binary_version=2.10.0
gtk_host=i686-redhat-linux-gnu
Name: GTK+
Description: GIMP Tool Kit (${target} target)
Version: 2.10.4
Requires: gdk-${target}-2.0 atk cairo
Libs: -L${libdir} -lgtk-${target}-2.0
Cflags: -I${includedir}/gtk-2.0
Obviously, the can themselves be specified as: -L/usr/lib-lgtk-{target} -2.0 -I/usr/include/gtk-2.0
Take a look at {target} as following:
[root@yx lib]# ls gt
gthumb/ gtk-2.0/ gtkhtml/
gtk/ gtk-sharp-2.0/ gtkmm-2.4/
[root@yx lib]# ls gtk-2.0/
2.10.0 2.4.0 immodules include modules
[root@yx lib]# ls gtk-sharp-2.0/
gconfsharp-schemagen.exe
[root@yx lib]# pwd
/usr/lib
So think-lgtk-{target} -2.0 {target} in the empty characters:
-lgtk-{target}-2.0====>-lgtk–2.0
At Last So:(theory generally :)
-L/usr/lib -lgtk-{target}-2.0 -I/usr/include/gtk-2.0 ====>
-L/usr/lib -lgtk–2.0 -I/usr/include/gtk-2.0
In fact some more:
Contrast pkg-config for gtk+-2.0 see 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
There are so many paths as below.
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`[/vc_column_text][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.