On Wed, Jul 17, 2013 at 09:56:10AM -0400, Slaven_Rezic via RT wrote:
Show quoted text> <URL:
https://rt.cpan.org/Ticket/Display.html?id=86988 >
>
> On 2013-07-17 04:41:28, ppisar wrote:
> > 804.031 cannot detect system libpng because the test forget to link
> > against zlib:
> >
> > system('pkg-config --exists libpng');
> > if ($? == 0) {
> > chomp($libpng_cflags = `pkg-config --cflags libpng`);
> > chomp($libpng_libs = `pkg-config --libs libpng`);
> > } else {
> > warn "'pkg-config libpng' failed, continue with fallback values
> > for cflags and libs...\n";
> > $libpng_cflags = '-I/usr/local/include';
> > $libpng_libs = '-lpng -lz -lm';
> > }
> >
> > if ($Tk::MMtry::VERSION ge '4.007' &&
> > try_run("config/has_png.c",[$libpng_cflags],[$libpng_libs]))
> >
> > And config/has_png.c calls zlibVersion().
> >
> > My libpng does not output zlib as build-time dependency:
> >
> > # pkg-config --libs libpng
> > -lpng16
> >
> > I propose to add '-lz' to the $libpng_libs.
>
> Which system is this?
Fedora 18 and 20.
Show quoted text> On my debian system, -lz is not listed in the pkg-config output,
That's correct.
Show quoted text> but things are working nevertheless.
Probably because of opportunistic linker in your distribution. libpng links
itself to libz what can make libz symbols available to the test program.
However this is not portable. If libpng stopped using zlib, then your test
program would miss symbols from libz.
If the test program includes zlib headers and calls functions from lzib, then
it must be linked to libz explictly. Otherwise strict linker will complain
about unresolved zlibVersion symbol.
Show quoted text> On my freebsd system, the output of pkg-config includes -lz:
>
> $ pkg-config --libs libpng -L/usr/local/lib -lpng -lz -lm
>
Because some linkers require repeating libraries that are needed by already
linked libraries. Sometimes it's just a dummy fall-back for case when
a library is static but it has dynamic dependenies.
Show quoted text> So it seems to me that the output of pkg-config should include -lz if it's
> needed?
>
Unless libpng uses zlib data structures to pass data between application and
libpng, hence including zlib headers through libpng headers (i.e. #include
<png.h> is enough to use definitions from <zlib.h> without including <zlib.h>
explicitly), there is no need to link each libpng aplication to libz, thus
pkg-config should not output -lz.
-- Petr