【问题标题】:How does the linking process differ when using Requires vs Requires.private in pkg-config?在 pkg-config 中使用 Requires 与 Requires.private 时,链接过程有何不同?
【发布时间】:2017-08-01 14:56:34
【问题描述】:

我指的是guide to pkg-config 学习如何写一个。

在某处,它提到了以下关于 RequiresRequires.private 字段的内容。

RequiresRequires.private 定义了 图书馆。通常首选使用的私有变体 需要避免将不必要的库暴露给程序 正在与您的图书馆链接。如果程序不会使用 所需库的符号,不应直接链接到 那个图书馆。

我了解其中的含义,但我不完全了解这两种情况下的链接过程有何不同。 即给定这两个版本的 *.pc,链接过程将如何工作?

bar1.pc:

prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: bar
Description: The bar library
Version: 2.1.2
Requires.private: foo >= 0.7
Cflags: -I${includedir}
Libs: -L${libdir} -lbar

bar2.pc:

prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: bar
Description: The bar library
Version: 2.1.2
Requires: foo >= 0.7
Cflags: -I${includedir}
Libs: -L${libdir} -lbar

【问题讨论】:

    标签: shared-libraries pkg-config


    【解决方案1】:

    对于动态链接,所有Requires 库都将成为程序 的依赖项(app/lib 链接到您的lib)。如果你使用Requires.private,只有你的库会链接依赖,而不是程序。

    Requires:

    +----------------+   +----------------+   +---------------+
    | program        |-->| your lib       |-->| required lib  |
    |                |   +----------------+   |               |
    |                |----------------------->|               |
    +----------------+                        +---------------+
    

    Requires.private:

    +----------------+   +----------------+   +---------------+
    | program        |-->| your lib       |-->| required lib  |
    +----------------+   +----------------+   +---------------+
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 2011-03-31
      • 1970-01-01
      相关资源
      最近更新 更多