OpenPrinting / libppd

Apache License 2.0
2 stars 13 forks source link

build: use pkg-config to find zlib #41

Closed orbea closed 5 months ago

orbea commented 5 months ago

When building with slibtool it fails with undefined references for -lz because the build sets -no-undefined in the LDFLAGS. This doesn't fail with GNU libtool because they silently ignore -no-undefined.

To solve this the build now uses PKG_CHECK_MODULES to find zlib.

Gentoo issue: https://bugs.gentoo.org/920273

orbea commented 5 months ago

I only now see the similar already existing PR...

https://github.com/OpenPrinting/libppd/pull/32

I'll leave this open for visibility, but I don't mind which version is preferred.

tillkamppeter commented 5 months ago

Merged pull request #32. Thanks for the reminder by this pull request.

eli-schwartz commented 5 months ago

Note the fairly obvious difference between my PR and this later one is that mine included fallback code for when zlib is installed by the host system without a pkg-config file, e.g. some versions of *BSD that include it in their monorepo without building via the official zlib build system.

EDIT:

This doesn't fail with GNU libtool because they silently ignore -no-undefined.

The libtool flag is unrelated to the ld.bfd flag, and libtool behaves exactly as you want it to if you add -Wl,--no-undefined to LDFLAGS.

orbea commented 5 months ago

The libtool flag is unrelated to the ld.bfd flag, and libtool behaves exactly as you want it to if you add -Wl,--no-undefined to LDFLAGS.

FWIW, Darwin doesn't have-Wl,--no-undefined and instead expects -Wl,-undefined,error. I am unsure what GNU libtool does on Darwin, but slibtool respects -no-undefined on both platforms.

eli-schwartz commented 5 months ago

The libtool flag is unrelated to the ld.bfd flag, and libtool behaves exactly as you want it to if you add -Wl,--no-undefined to LDFLAGS.

FWIW, Darwin doesn't have-Wl,--no-undefined and instead expects -Wl,-undefined,error. I am unsure what GNU libtool does on Darwin, but slibtool respects -no-undefined on both platforms.

GNU libtool documents the flag as meaning "it is safe or not safe to build shared libraries in a cygwin environment".

When I say it doesn't have anything to do with the ld.bfd flag, I'm not exaggerating. It is literally unrelated. It is not topical to the topic of asking the linker to error out on undefined symbols.

orbea commented 5 months ago

I don't know what you mean by "ld.bfd", -no-undefined is a libtool flag which passes the appropriate flag to the system's linker such as -Wl,--no-undefined. GNU libtool for a very long time simply does nothing on most platforms (?) while slibtool will actually use the appropriate linker flag which finds issues like this that have previously gone unnoticed.

There may also be issues with using -Wl,--no-undefined on OpenBSD when building a library.

https://bugs.freedesktop.org/show_bug.cgi?id=76856 https://marc.info/?l=openbsd-tech&m=170284912609821&w=2