为什么 pkg-config 用另一个默认的前缀覆盖“前缀”?

问题描述 投票:0回答:1

我在使用 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 已更新至最新版本。

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

x264 msys2 pkg-config
1个回答
4
投票

看起来您的 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 手册页(源代码)

pkg-config 手册页(渲染)

附注MSYS2 有几个 pkg-config 软件包。你应该使用

mingw64/mingw-w64-x86_64-pkg-config
mingw32/mingw-w64-i686-pkg-config
。不要使用
msys/pkg-config

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.