【问题标题】:pkg-config reports paths different than the ones in the pc filepkg-config 报告的路径与 pc 文件中的路径不同
【发布时间】:2019-11-24 14:17:58
【问题描述】:

我已经用 CMake 构建了 libpng,并将它生成的 .pc 文件添加到 pck-config 的目录中。

需要 libpng 的项目无法构建,因为 pkg-config 在像 pkg-config --cflags libpng 这样调用时提供了错误的路径

调试输出:

$ pkg-config.exe --debug libpng
no output option set, defaulting to --exists
Error printing disabled by default due to use of output options --exists, --atleast/exact/max-version, --list-all or no output option at all. Value of --print-errors: 0
Error printing disabled
Adding virtual 'pkg-config' package to list of known packages
Looking for package 'libpng'
Looking for package 'libpng-uninstalled'
Reading 'libpng' from file 'C:\mingw64\mingw64\lib\pkgconfig\libpng.pc'
Parsing package file 'C:\mingw64\mingw64\lib\pkgconfig\libpng.pc'
  line>prefix=C:/Program Files (x86)/libpng
 Variable declaration, 'prefix' overridden with 'C:/mingw64/mingw64'
  line>exec_prefix=C:/Program Files (x86)/libpng
 Variable declaration, 'exec_prefix' has value 'C:/Program Files (x86)/libpng'
  line>libdir=C:/Program Files (x86)/libpng/lib
 Variable declaration, 'libdir' has value 'C:/mingw64/mingw64/lib'
  line>includedir=C:/Program Files (x86)/libpng/include/libpng16
 Variable declaration, 'includedir' has value 'C:/mingw64/mingw64/include/libpng16'
  line>
  line>Name: libpng
  line>Description: Loads and saves PNG files
  line>Version: 1.6.37
  line>Requires: zlib
  line>Libs: -L${libdir} -lpng16
  line>Libs.private: -lz -lm
Unknown keyword 'Libs.private' in 'C:\mingw64\mingw64\lib\pkgconfig\libpng.pc'
  line>Cflags: -I${includedir}
Path position of 'libpng' is 3
Adding 'libpng' to list of known packages

手册指出:

Windows 专业

如果在与通常约定匹配的目录中找到 .pc 文件(即以 \lib\pkgconfig 结尾),则假定该包的前缀是找到该文件的目录的祖父级,并且相应地,该文件的前缀变量被覆盖。

但是,.pc 文件中没有任何${prefix}。我不知道替换来自哪里以及如何修复它们。只有prefix 被报告为被覆盖,rest 被报告为“有值”但打印的路径不是文件中声明的路径,它们甚至不存在。

【问题讨论】:

    标签: pkg-config


    【解决方案1】:

    这个问题的解决方案其实是Why pkg-config overrides 'prefix' with another default one?的一个副本

          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 禁用该功能,但它在 Windows 上默认启用,并且查询 pkg-config 的程序不添加此标志。我不知道这个功能有什么意义,但解决方案相当简单:

    • .pc 文件移动到未命名为pkgconfig 的目录中
    • 将此目录添加到PKG_CONFIG_PATH环境变量中

    【讨论】:

      猜你喜欢
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多