今天在看LTTng 文档的时候看到这个指令。
gcc -o notif-app notif-app.c $(pkg-config --cflags --libs lttng-ctl)
查了一下 pkg-config是一个linux下的命令,用于获得某一个库/模块的所有编译相关的信息。
pkg-config --cflags --libs lttng-ctl执行结果:
-I/usr/local/include -L/usr/local/lib -llttng-ctl
那以后编译程序连接很多安装的库和接口的时候就可以省力很多了。
DESCRIPTION
The pkg-config program is used to retrieve information about installed libraries in the
system. It is typically used to compile and link against one or more libraries. Here is
a typical usage scenario in a Makefile:
program: program.c
cc program.c $(pkg-config --cflags --libs gnomeui)
pkg-config retrieves information about packages from special metadata files. These files
are named after the package, and has a .pc extension. On most systems, pkg-config looks
in /usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkgconfig and
/usr/local/share/pkgconfig for these files. It will additionally look in the colon-
separated (on Windows, semicolon-separated) list of directories specified by the
PKG_CONFIG_PATH environment variable.
The package name specified on the pkg-config command line is defined to be the name of the
metadata file, minus the .pc extension. If a library can install multiple versions
simultaneously, it must give each version its own name (for example, GTK 1.2 might have
the package name "gtk+" while GTK 2.0 has "gtk+-2.0").
In addition to specifying a package name on the command line, the full path to a given .pc
file may be given instead. This allows a user to directly query a particular .pc file.
在Makefile中不能像在shell中那样使用!!!!!!
要这样写:
LTTng_Lib = $(shell pkg-config --cflags --libs lttng-ctl)
all:
g++ my_app.cpp $(LTTng_Lib)
可能是在Makefile中不能等调用shell返回吧。