I have an issue in using pkg-config to link some libraries to a program. The problem is 'prefix' variable in each library pkg-config files (*.pc) are overridden with an unwanted directory leading to building the program could not find the library's header and lib files.
Here, one of '*.pc' files, x264.pc:
prefix=/e/x264/x64-windows-rel
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
...
I run this from MSYS2 terminal:
pkg-config --cflags --debug x264
This is some of the output it traced out:
...
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'
...
Note that MSYS2 and pkg-config are updated to newest versions.
Could anybody tell me why it happens and how to solve the issue without renaming 'prefix' to something else.? Thanks.
Looks like your pkg-config was compiled with --enable-define-prefix
option (look like default for Windows targets) and your .pc file is located in directory with pkgconfig
name (D:/msys64/usr/local/lib/pkgconfig\x264.pc
). Btw why is .pc file installed in D:/msys64/usr/local/lib/pkgconfig
while libraries are installed elsewhere?
Here is quote from pkg-config manual page:
--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.
So you can disable this behavior by --dont-define-prefix
option.
pkg-config manual page (source code)
pkg-config manual page (rendered)
P.S. MSYS2 have few pkg-config packages. And you supposed to use mingw64/mingw-w64-x86_64-pkg-config
or mingw32/mingw-w64-i686-pkg-config
. Do NOT use msys/pkg-config
.