After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 630910 - glib: build is broken when zlib is not on a standard location
glib: build is broken when zlib is not on a standard location
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: build
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2010-09-29 15:14 UTC by Felipe Contreras (banned)
Modified: 2011-09-09 00:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed fix. (913 bytes, patch)
2010-09-29 15:14 UTC, Felipe Contreras (banned)
none Details | Review
Alternative proposed fix (876 bytes, patch)
2010-09-29 17:08 UTC, Felipe Contreras (banned)
committed Details | Review
gio.pc.in: depend on zlib (848 bytes, patch)
2010-11-06 17:38 UTC, Felipe Contreras (banned)
none Details | Review

Description Felipe Contreras (banned) 2010-09-29 15:14:49 UTC
Created attachment 171341 [details] [review]
Proposed fix.

This is the error:
 gzlibcompressor.c:26: fatal error: zlib.h: No such file or directory

This comes from bug #623473; my original patch worked, but apparently somebody doesn't appreciate lines of code that are actually tested and thinks they can be discarded without any comment and claiming the patch is now theirs... Never-mind the brokenness.

Hopefully this patch is as minimal as it gets, and it can't be miss-represented as unnecessary, or whatever.
Comment 1 Tor Lillqvist 2010-09-29 15:21:43 UTC
Isn't that what CPPFLAGS and LDFLAGS are for?
Comment 2 Felipe Contreras (banned) 2010-09-29 15:46:58 UTC
(In reply to comment #1)
> Isn't that what CPPFLAGS and LDFLAGS are for?

Nope, CPPFLAGS can be overridden by the user... An alternative would be to do:

libgio_2_0_la_CPPFLAGS = $(ZLIB_CFLAGS) $(AM_CPPFLAGS)

I'm testing that now.
Comment 3 Tor Lillqvist 2010-09-29 16:06:50 UTC
That's what I mean, that the "user" (the person building glib) can pass CPPFLAGS and LDFLAGS as necessary for it to find zlib headers and libraries.
Comment 4 Felipe Contreras (banned) 2010-09-29 17:08:18 UTC
Created attachment 171348 [details] [review]
Alternative proposed fix

Just to avoid other "rewrites".
Comment 5 Felipe Contreras (banned) 2010-09-29 17:10:21 UTC
(In reply to comment #3)
> That's what I mean, that the "user" (the person building glib) can pass
> CPPFLAGS and LDFLAGS as necessary for it to find zlib headers and libraries.

No, that's the whole point of pkg-config:
http://en.wikipedia.org/wiki/Pkg-config

This should work (even if libz is installed in /opt/libz):
gcc -o test test.c $(pkg-config --libs --cflags libz)
Comment 6 Tor Lillqvist 2010-09-29 17:31:00 UTC
I know fully well what the point of pkg-config is. But do the zlib maintainers? (OK, so in version 1.2.5 they apparently do. So should we require version 1.2.5?)
Comment 7 Felipe Contreras (banned) 2010-09-29 18:25:17 UTC
(In reply to comment #6)
> I know fully well what the point of pkg-config is. But do the zlib maintainers?
> (OK, so in version 1.2.5 they apparently do. So should we require version
> 1.2.5?)

That is irrelevant; the code to use pkg-config is already there, but broken.

And even if it wasn't, and you use an old zlib:
 * You can define ZLIB_CFLAGS and ZLIB_LIBS
 * You can write your own .pc file
 * You can rely on your distribution adding the .pc file (like Fedora does, although it's anyway in /usr)
 * Or even as you say, use CPPFLAGS and LDFLAGS

The point is that adding the pkg-config stuff only helps.
Comment 8 Felipe Contreras (banned) 2010-11-06 17:38:02 UTC
Created attachment 173962 [details] [review]
gio.pc.in: depend on zlib

And 'pkg-config --libs gio' is not returning the right flags.
Comment 9 Christian Persch 2010-11-07 00:24:28 UTC
(In reply to comment #8)
> Created an attachment (id=173962) [details] [review]
> gio.pc.in: depend on zlib
> 
> And 'pkg-config --libs gio' is not returning the right flags.

IMO this patch is wrong, since it a) always adds the zlib dep to the pc file, even if gio isn't compiled with zlib support, and b) if the zlib dep  should be put in the pc file at all (which I take no position on here), it should be in Requires.private, not Requires.
Comment 10 Felipe Contreras (banned) 2010-11-07 10:02:57 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > Created an attachment (id=173962) [details] [review] [details] [review]
> > gio.pc.in: depend on zlib
> > 
> > And 'pkg-config --libs gio' is not returning the right flags.
> 
> IMO this patch is wrong, since it a) always adds the zlib dep to the pc file,
> even if gio isn't compiled with zlib support

gio is always compiled with zlib support.

> and b) if the zlib dep  should be
> put in the pc file at all (which I take no position on here), it should be in
> Requires.private, not Requires.

That's what I thought, but the linker is failing to detect the dependency automatically, I don't know why.
Comment 11 Felipe Contreras (banned) 2011-02-09 23:55:33 UTC
Hellooo?
Comment 12 Colin Walters 2011-02-10 00:54:32 UTC
(In reply to comment #11)
> Hellooo?

What operating system and version is this, and how are you configuring the build?
Comment 13 Felipe Contreras (banned) 2011-02-10 01:16:27 UTC
(In reply to comment #12)
> (In reply to comment #11)
> > Hellooo?
> 
> What operating system and version is this, and how are you configuring the
> build?

Have you even looked at the patches? They are obvious fixes.

 1) remove zlib-devel
 2) install zlib to /opt/zlib
 3) export PKG_CONFIG_PATH=/opt/zlib/lib/pkgconfig

See for yourself.
Comment 14 Colin Walters 2011-02-10 01:21:33 UTC
(In reply to comment #13)
> (In reply to comment #12)
> > (In reply to comment #11)
> > > Hellooo?
> > 
> > What operating system and version is this, and how are you configuring the
> > build?
> 
> Have you even looked at the patches? They are obvious fixes.

I agree with Christian that adding zlib to Requires is definitely wrong; it would be Requires.private if anything.

If you added it to Requires, it would force every process linking to gio to also link to zlib, which is clearly wrong, since it's an implementation detail, not part of the API.
Comment 15 Felipe Contreras (banned) 2011-02-10 02:57:02 UTC
(In reply to comment #14)
> I agree with Christian that adding zlib to Requires is definitely wrong; it
> would be Requires.private if anything.
> 
> If you added it to Requires, it would force every process linking to gio to
> also link to zlib, which is clearly wrong, since it's an implementation detail,
> not part of the API.

Suppose zlib is installed in /opt/zlib, and glib in /opt/glib, how do you propose to make this work?

arm-linux-gcc $(pkg-config --cflags --libs gio-2.0) test.c -o test
/opt/arm-2009q3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: libz.so.1, needed by /opt/tmp/glib/lib/libgio-2.0.so, not found (try using -rpath or -rpath-link)
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `inflateReset'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `inflateEnd'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `deflate'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `deflateInit_'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `inflateInit2_'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `deflateSetHeader@ZLIB_1.2.2'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `inflate'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `deflateEnd'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `deflateReset'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `inflateGetHeader@ZLIB_1.2.2'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `inflateInit_'
/opt/tmp/glib/lib/libgio-2.0.so: undefined reference to `deflateInit2_'
collect2: ld returned 1 exit status

Clearly, the linker has no way of finding libz.so.1. It looks like -rpath-link should do the trick, but it doesn't here.

Anyway, that's a separate issue, attachment #171348 [details] is the important one.
Comment 16 Colin Walters 2011-02-10 03:01:22 UTC
(In reply to comment #15)
>
> arm-linux-gcc $(pkg-config --cflags --libs gio-2.0) test.c -o test

What does $(pkg-config --cflags --libs gio-2.0) output if zlib was in Requires.private?  And what version of pkg-config?
Comment 17 Felipe Contreras (banned) 2011-02-10 03:07:24 UTC
(In reply to comment #16)
> (In reply to comment #15)
> >
> > arm-linux-gcc $(pkg-config --cflags --libs gio-2.0) test.c -o test
> 
> What does $(pkg-config --cflags --libs gio-2.0) output if zlib was in
> Requires.private?  And what version of pkg-config?

% pkg-config --cflags --libs gio-2.0
-pthread -I/opt/tmp/glib/include/glib-2.0 -I/opt/tmp/glib/lib/glib-2.0/include  -pthread -L/opt/tmp/glib/lib -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0

This is linux; Requires.private is ignored for shared libraries.

% pkg-config --version
0.25
Comment 18 Colin Walters 2011-02-10 04:05:40 UTC
(In reply to comment #17)
> (In reply to comment #16)
> > (In reply to comment #15)
> > >
> > > arm-linux-gcc $(pkg-config --cflags --libs gio-2.0) test.c -o test
> > 
> > What does $(pkg-config --cflags --libs gio-2.0) output if zlib was in
> > Requires.private?  And what version of pkg-config?
> 
> % pkg-config --cflags --libs gio-2.0
> -pthread -I/opt/tmp/glib/include/glib-2.0 -I/opt/tmp/glib/lib/glib-2.0/include 
> -pthread -L/opt/tmp/glib/lib -lgio-2.0 -lgobject-2.0 -lgmodule-2.0
> -lgthread-2.0 -lrt -lglib-2.0
> 
> This is linux; Requires.private is ignored for shared libraries.

Well, it's still useful for dependency generator implementations (think rpm, etc.).

However, one thing I don't understand in this situation is why pkg-config doesn't add -L /opt/zlib/lib.
Comment 19 Felipe Contreras (banned) 2011-02-10 10:57:39 UTC
(In reply to comment #18)
> (In reply to comment #17)
> > This is linux; Requires.private is ignored for shared libraries.
> 
> Well, it's still useful for dependency generator implementations (think rpm,
> etc.).

And static libraries.

> However, one thing I don't understand in this situation is why pkg-config
> doesn't add -L /opt/zlib/lib.

Because it's in the private libs, but that only matters when linking the libraries, not the dependencies.
Comment 20 Felipe Contreras (banned) 2011-02-27 23:19:49 UTC
Ok, I've removed the patch for the .pc file since apparently pkg-config is at fault. Now, can we get the obviously good fix in?
Comment 21 Felipe Contreras (banned) 2011-04-30 08:23:44 UTC
Hellooooo?

What's wrong with attachment #171348 [details]?
Comment 22 Colin Walters 2011-04-30 13:25:15 UTC
Comment on attachment 171348 [details] [review]
Alternative proposed fix

Looks fine to me.