【问题标题】:Why pkg-config overrides 'prefix' with another default one?为什么 pkg-config 用另一个默认值覆盖“前缀”?
【发布时间】:2018-09-21 09:19:12
【问题描述】:

我在使用 pkg-config 将某些库链接到程序时遇到问题。问题是每个库中的“前缀”变量 pkg-config 文件 (*.pc) 被不需要的目录覆盖,导致构建程序找不到库的头文件和 lib 文件。

这里是“*.pc”文件之一,x264.pc:

prefix=/e/x264/x64-windows-rel  
exec_prefix=${prefix}   
libdir=${exec_prefix}/lib   
includedir=${prefix}/include    
...

我从 MSYS2 终端运行这个:

pkg-config --cflags --debug x264

这是它追踪到的一些输出:

...
 Parsing package file 'D:/msys64/usr/local/lib/pkgconfig\x264.pc'
 line>prefix=/e/x264/x64-windows-rel
 Variable declaration, 'prefix' overridden with 'D:/msys64/usr/local'
...

请注意,MSYS2 和 pkg-config 已更新到最新版本。

谁能告诉我为什么会发生这种情况以及如何在不将“前缀”重命名为其他名称的情况下解决问题。? 谢谢。

【问题讨论】:

  • 为什么用这个路径配置libx264? x264.pc 的默认值为 prefix=/usr/local。或者你在问为什么用 'D:/msys64/usr/local' 覆盖?
  • 你设置PKG_CONFIG_LIBDIR环境变量了吗?
  • @nobody555 在 pkg 文件中设置任何有效路径都是合法的,我想 pkg-config 找到我的路径而不是任何默认路径。我设置了 PKG_CONFIG_PATH 但没有设置 PKG_CONFIG_LIBDIR。

标签: x264 msys2 pkg-config


【解决方案1】:

看起来您的 pkg-config 是使用 --enable-define-prefix 选项编译的(看起来像 Windows 目标的默认值),并且您的 .pc 文件位于名称为 pkgconfig (D:/msys64/usr/local/lib/pkgconfig\x264.pc) 的目录中。顺便说一句,为什么 .pc 文件安装在 D:/msys64/usr/local/lib/pkgconfig 中,而库安装在其他地方?

这是来自 pkg-config 手册页的引用:

    --define-prefix
          --dont-define-prefix  These  options  control whether pkg-config
          overrides the value of the variable prefix  in  each  .pc  file.
          With  --define-prefix, pkg-config uses the installed location of
          the .pc file to determine the prefix. --dont-define-prefix  pre-
          vents this behavior. The default is usually --define-prefix.

          When this feature is enabled and a .pc file is found in a direc-
          tory named pkgconfig, the prefix for that package is assumed  to
          be  the  grandparent  of the directory where the file was found,
          and the prefix variable is overridden for that file accordingly.

          If  the value of a variable in a .pc file begins with the origi-
          nal, non-overridden, value of  the  prefix  variable,  then  the
          overridden value of prefix is used instead. This allows the fea-
          ture to work even when the variables have been expanded  in  the
          .pc file.

因此您可以通过--dont-define-prefix 选项禁用此行为。

pkg-config manual page (source code)

pkg-config manual page (rendered)

附: MSYS2 的 pkg-config 软件包很少。你应该使用mingw64/mingw-w64-x86_64-pkg-configmingw32/mingw-w64-i686-pkg-config。不要使用msys/pkg-config

【讨论】:

  • 指出原因是对的。对于您的问题,我将库放在其他地方而不是相对于“usr/local/lib/pkgconfig”的一个,因为该库被其他程序使用。此外,我发现 MSYS2 的子文件夹中存在两个 pkg-config.exe 实例,它们的版本均为 0.29.2,但每个实例的行为方式各不相同:默认情况下,msys64/mingw64/bin/pkg-config.exe 会覆盖“前缀”。 msys64/usr/bin/pkg-config.exe 默认不覆盖'prefix'。
猜你喜欢
  • 1970-01-01
  • 2018-06-26
  • 1970-01-01
  • 1970-01-01
  • 2011-12-20
  • 1970-01-01
  • 2022-06-23
  • 1970-01-01
相关资源
最近更新 更多