pkg-config

pkg-config is computer software that provides a unified interface for querying installed libraries for the purpose of compiling software from its source code. pkg-config was originally designed for Linux but is now also available for the various BSDs, Microsoft Windows, Mac OS X, and Solaris.

It outputs various information about installed libraries. This information may include:

Parameters for C or C++ compiler

Parameters for linker

Version of the package in question

The first implementation was written in shell. Later, it was rewritten in C using the GLib library.

语法

Synopsis

When a library is installed (automatically through the use of an RPM, deb, or other binary packaging system or by compiling from the source), a .pc file should be included and placed into a directory with other .pc files (the exact directory is dependent upon your system and outlined in the pkg-config man page). This file has several entries.

These entries typically contain a list of dependent libraries that programs using the package also need to compile. Entries also typically include the location of header files, version information and a description.

pc配置文件格式.

Here is an example .pc file for libpng:

 prefix=/usr/local

 exec_prefix=${prefix}

 libdir=${exec_prefix}/lib

 includedir=${exec_prefix}/include

 

 Name: libpng

 Description: Loads and saves PNG files

 Version: 1.2.8

 Libs: -L${libdir} -lpng12 -lz

 Cflags: -I${includedir}/libpng12

This file demonstrates how libpng informs that its libraries can be found in /usr/local/lib and its headers in /usr/local/include, that the library name is libpng, and that the version is 1.2.8. It also gives the additional linker flags that are needed to compile code that uses this library.

编译时使用pkg-config提取libpng对应的依赖库和头文件目录.

Here is an example of usage of pkg-config while compiling:

$ gcc -o test test.c $(pkg-config --libs --cflags libpng)

PostgreSQL中取一个libpq.pc的例子 : 

[root@150 pkgconfig]# pwd

/opt/pgsql/lib/pkgconfig

[root@150 pkgconfig]# ll

total 16

-rw-r--r--. 1 root root 273 Aug  5 11:24 libecpg_compat.pc

-rw-r--r--. 1 root root 245 Aug  5 11:24 libecpg.pc

-rw-r--r--. 1 root root 228 Aug  5 11:24 libpgtypes.pc

-rw-r--r--. 1 root root 251 Aug  5 11:24 libpq.pc

[root@150 pkgconfig]# cat libpq.pc 

Name: libpq

Description: PostgreSQL libpq library

Url: http://www.postgresql.org/

Version: 9.3.5

Requires: 

Requires.private: 

Cflags: -I/opt/pgsql9.3.5/include

Libs: -L/opt/pgsql9.3.5/lib -lpq

Libs.private:  -lssl -lcrypto -lcrypt -lldap_r -lpthread

[参考]

1. man pkg-config

2. http://en.wikipedia.org/wiki/Pkg-config

时间: 2024-08-01 11:30:08

pkg-config的相关文章

golang之pkg(包)

一.概述 Golang拥有超过100个标准包(可用go list std |wc -l查看) 任何包系统设计的目的都是简化大型程序的设计和维护工作,通过将一组相关的特性放进一个独立的模块以便于理解和更新,在每个模块更新的同时保持和程序中其他模块的相对独立,这种模块化的特性允许每个包能被其他的不同项目共享和重用,在项目范围内.全局范围内的复用: 每个包一般都定义了一个不同的名字空间用于它内部的每个标识符的访问. 每个名字空间关联到一个特定的包, 让我们给类型. 函数等选择简短明了的名字, 这样可以

MonoDevelop的app.config问题

 MonoDevelop的app.config问题    最近正在看Unity2.0的DI和AOP.说实话,真不入Spring.NET来的方便.无论是从代码配置还是在配置文件里配置,量太多.  说起来配置,代码配置无论如何都是不如配置文件里配置灵活.尤其,DI和AOP本来就是用来处理需求多变的情况的,不可能  每次需求变化了都修改代码然后重新编译一次.    MomoDevelop可以认为是VS的跨平台版(以下简称MD).编译用的是Mono,.NET Framework的跨平台版.  MD和VS

pom xml-maven项目中servlet.xml中出现 "oscache:config" is not bound.错误

问题描述 maven项目中servlet.xml中出现 "oscache:config" is not bound.错误 在pom.xml中加了依赖oscache的jar包.代码如下:com.opensymphonyoscache2.4.1 在servlet.xml中出现The prefix ""oscache"" for element ""oscache:config"" is not bound.错误

asp.net下加密Config的方法

复制代码 代码如下: <appSettings> <!-- 连接字符串是否加密 --> <add key="ConStringEncrypt" value="false"/> <!-- 连接字符串,(可以扩展支持不同数据库)如果是加密方式,上面一项要设置为true,如果是明文server=127.0.0.1;database=codematic;uid=sa;pwd=,上面设置为false --> <add ke

存储.NET应用程序到定制的XML .config文件中

xml|程序   在决定分布基于.Net框架的应用程序之前,要决定怎样管理公共程序的设置.要提高代码的重用率和应用程序的互用性,所有的应用程序 – WEB, Windows, Web服务,Windows 服务都要使用应用配置文件作为公共的方法来管理以应用为中心的信息.      系统配置 vs. 应用配置   当.NET的公共语言运行库(CLR)执行应用程序的时候,它会使用一系列的XML配置文件来设置运行环境的基本属性.举例说,如果执行WEB应用程序,那么CLR就会询问WEB.config文件来

在web.config中添加连接字符串

web|字符串|字符串 web.config中的文件如下: <?xml version="1.0" encoding="utf-8" ?><configuration><appSettings>      <add key="constring"  value="integrated security=SSPI;data source=localhost;initial catalog=教务管理

如何配置Web.config文件 for ASP.NET

一.认识Web.config文件   Web.config文件是一个XML文本文件,它用来储存 ASP.NET Web 应用程序的配置信息(如最常用的设置ASP.NET Web 应用程序的身份验证方式),它可以出现在应用程序的每一个目录中.当你通过VB.NET新建一个Web应用程序后,默认情况下会在根目录自动创建一个默认的  Web.config文件,包括默认的配置设置,所有的子目录都继承它的配置设置.如果你想修改子目录的配置设置,你可以在该子目录下新建一个Web.config文件.它可以提供除

把数据库连接信息写在web.config文件里(vs.net2003)

web|数据|数据库|数据库连接|数据库连接 如果我们把数据库连接信息也就是数据库连接字符串写在web.config里,不但加强了程序的安全,同时也极大的方便了程序的修改.    在web.config文件里添加关键字key是通过<appSettings>标记来实现的,但是appSettings标记通常放在<system.web>.....</system.web>标记外面.例: <configration>     <appSettings>

利用程序动态管理Web.config文件

web|程序|动态   Web.config文件假设有如下需要管理的配置信息:  <appSettings>    <add key="SiteTitle" value="站点名称" />    <add key="SiteUrl" value="主页网址" />    <add key="SiteLogo" value="站点Logo" /&g

读取config文件的两种方法

  项目进入测试阶段,暂时闲下来了,写点笔记. 读取web.config 或者 app.config中自定义配置的值的属性,常用2种方法. 假设有如下配置: <appSettings>  <add key="A" value="config with A"/>  <add key="B" value="config with B"/> </appSettings>  using