Xeverous
Xeverous

Reputation: 1014

pkg-config reports paths different than the ones in the pc file

I have build libpng with CMake and added it's generated .pc file to pck-config's directory.

Projects which require libpng fail to build because pkg-config supplies wrong paths when called like pkg-config --cflags libpng

Debug output:

$ 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

The manual states:

Windows Specialities

If a .pc file is found in a directory that matches the usual conventions (i.e., ends with \lib\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.

However, I do not have any ${prefix} in the .pc file. I have no idea where the replacements come from and how to fix them. Only prefix is reported to be overriden, rest is reported "has value" but the printed paths are not the ones declared in the file, they do not even exist.

Upvotes: 0

Views: 1288

Answers (1)

Xeverous
Xeverous

Reputation: 1014

The solution to this is actually a duplicate of 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.

The feature can be disabled with --dont-define-prefix but it is on by default on Windows and programs which query pkg-config do not add this flag. I have no idea what's the point of this feature but the solution is fairly straightforward:

  • move .pc files to a directory that is not named pkgconfig
  • add this directory to PKG_CONFIG_PATH environmental variable

Upvotes: 0

Related Questions