pkg-config does not always de-duplicate flags entries, leading to potentially huge commandlines
Using pkg-config master on Windows.
Flags de-duplication for flags is not happening. This in turn causes the generation of a huge commandline when linking a project against multiple libraries, which cause the command to fail because is too long.
Example of failure on Windows:
The filename or extension is too long. (os error 206)
Minimal test case:
foo.pc
:
prefix=/usr/local
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
Name: Foo
Description: foo
URL: https://foo.org/
Version: 1.0
Requires:
Conflicts:
Libs: -L${libdir} -lfoo -lbaz
Libs.private:
Cflags: -I${includedir}/foo
bar.pc
:
prefix=/usr/local
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
Name: Bar
Description: bar
URL: https://bar.org/
Version: 2.0
Requires: foo
Requires.private:
Conflicts:
Libs: -L${libdir} -lbaz
Cflags: -I${includedir}/bar
Command and output:
$ pkg-config --libs bar
-L/usr/local/lib -lbaz -lfoo -lbaz
Debug command and output:
$ ./pkg-config --version
0.29.2
$ pkg-config --debug --libs bar
$ ./pkg-config --debug --libs bar
Error printing enabled by default due to use of output options besides --exists, --atleast/exact/max-version or --list-all. Value of --silence-errors: 0
Error printing enabled
Adding virtual 'pkg-config' package to list of known packages
Looking for package 'bar'
Looking for package 'bar-uninstalled'
Reading 'bar' from file 'test.pkgconfig/bar.pc'
Parsing package file 'test.pkgconfig/bar.pc'
line>prefix=/usr/local
Variable declaration, 'prefix' has value '/usr/local'
line>exec_prefix=${prefix}
Variable declaration, 'exec_prefix' has value '/usr/local'
line>libdir=${prefix}/lib
Variable declaration, 'libdir' has value '/usr/local/lib'
line>includedir=${prefix}/include
Variable declaration, 'includedir' has value '/usr/local/include'
line>
line>Name: Bar
line>Description: bar
line>URL: https://bar.org/
line>Version: 2.0
line>Requires: foo
line>Requires.private:
line>Conflicts:
line>Libs: -L${libdir} -lbaz
line>Cflags: -I${includedir}/bar
Path position of 'bar' is 1
Adding 'bar' to list of known packages
Searching for 'bar' requirement 'foo'
Looking for package 'foo'
Looking for package 'foo-uninstalled'
Reading 'foo' from file 'test.pkgconfig/foo.pc'
Parsing package file 'test.pkgconfig/foo.pc'
line>prefix=/usr/local
Variable declaration, 'prefix' has value '/usr/local'
line>exec_prefix=${prefix}
Variable declaration, 'exec_prefix' has value '/usr/local'
line>libdir=${prefix}/lib
Variable declaration, 'libdir' has value '/usr/local/lib'
line>includedir=${prefix}/include
Variable declaration, 'includedir' has value '/usr/local/include'
line>
line>Name: Foo
line>Description: foo
line>URL: https://foo.org/
line>Version: 1.0
line>Requires:
line>Conflicts:
line>Libs: -L${libdir} -lfoo -lbaz
line>Libs.private:
line>Cflags: -I${includedir}/foo
Path position of 'foo' is 1
Adding 'foo' to list of known packages
post-recurse: bar foo
original: bar foo
sorted: bar foo
removing duplicate "-L/usr/local/lib"
removing duplicate "-L/usr/local/lib"
adding LIBS_L string "-L/usr/local/lib "
post-recurse: bar foo
removing duplicate "-lfoo"
removing duplicate "-lbaz"
adding LIBS_OTHER | LIBS_l string "-lbaz -lfoo -lbaz "
returning flags string "-L/usr/local/lib -lbaz -lfoo -lbaz"
-L/usr/local/lib -lbaz -lfoo -lbaz
Edited by Stefano Sabatini