pkg-config 查找库和用于编译

今天在看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返回吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小羊苏C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值