我指的是这个 guide to pkg-config用于学习如何编写。
在一处,它提到了以下有关 Requires 和 Requires.private 字段的内容。
Requires and Requires.private define other modules needed by the library. It is usually preferred to use the private variant of Requires to avoid exposing unnecessary libraries to the program that is linking with your library. If the program will not be using the symbols of the required library, it should not be linking directly to that library.
我理解其中的含义,但我不完全理解这两种情况下的链接过程有何不同。 即给定这两个版本的 *.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
最佳答案
对于动态链接,所有Requires
库都将成为程序 的依赖项(app/lib 链接到您的lib)。如果您使用 Requires.private
,只有您的库会链接依赖项,而不是程序。
需要
:
+----------------+ +----------------+ +---------------+
| program |-->| your lib |-->| required lib |
| | +----------------+ | |
| |----------------------->| |
+----------------+ +---------------+
使用Requires.private
:
+----------------+ +----------------+ +---------------+
| program |-->| your lib |-->| required lib |
+----------------+ +----------------+ +---------------+
关于shared-libraries - 在 pkg-config 中使用 Requires 与 Requires.private 时,链接过程有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45441250/