Description of problem: I am seeing a strange behavior of gcc when compiling the latest version of libsolv: /usr/bin/gcc -Wall -Wl,--as-needed CMakeFiles/deltainfoxml2solv.dir/deltainfoxml2solv.o -o deltainfoxml2solv -rdynamic libtoolstuff.a ../ext/libsolvext.so.0 ../src/libsolv.so.0 -ldb -lrpmio -lrpm -lexpat -lz -Wl,-rpath,/home/akozumpl/libsolv/build/ext:/home/akozumpl/libsolv/build/src: ../ext/libsolvext.so.0: undefined reference to `gzclose' ../ext/libsolvext.so.0: undefined reference to `gzdopen' ../ext/libsolvext.so.0: undefined reference to `gzopen64' ../ext/libsolvext.so.0: undefined reference to `gzread' ../ext/libsolvext.so.0: undefined reference to `gzwrite' There is a source in libsolvext.so that uses the mentioned zlib functions. However, notice that -lz is the last library on the command line and so ld should in any case be able to pick up any unresolved references from there, as stated by 'man ld': "If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. " If I move -lz forward on the command line, the linking passes fine: /usr/bin/gcc -Wall -Wl,--as-needed CMakeFiles/deltainfoxml2solv.dir/deltainfoxml2solv.o -o deltainfoxml2solv -rdynamic libtoolstuff.a ../ext/libsolvext.so.0 ../src/libsolv.so.0 -ldb -lz -lrpmio -lrpm -lexpat -Wl,-rpath,/bhome/akozumpl/libsolv/build/ext:/home/akozumpl/libsolv/build/src: gcc --version gcc (GCC) 4.7.0 20120507 (Red Hat 4.7.0-5)
Also see: https://github.com/openSUSE/libsolv/pull/22#issuecomment-11489652
First of all, this has nothing to do with gcc. I think --as-needed only adds libraries that are needed by the binary or library being linked, not for any libraries that were incorrectly linked before (from the above it looks like libsolvext.so.0 should have been linked against -lz when it uses it).
Thanks Jakub, you actually pointed us in the right direction: libsolvext.so should had already been linked against zlib but it was not. I wonder maybe 'ld' should scream when linking libsolvext.so then as it is clearly missing a dependency then. Also, the original problem still stands: combination of a missing shared dependency and using --as-needed can produce different results depending on the exact order of libraries being linked to the final binary.
This message is a reminder that Fedora 17 is nearing its end of life. Approximately 4 (four) weeks from now Fedora will stop maintaining and issuing updates for Fedora 17. It is Fedora's policy to close all bug reports from releases that are no longer maintained. At that time this bug will be closed as WONTFIX if it remains open with a Fedora 'version' of '17'. Package Maintainer: If you wish for this bug to remain open because you plan to fix it in a currently maintained version, simply change the 'version' to a later Fedora version prior to Fedora 17's end of life. Bug Reporter: Thank you for reporting this issue and we are sorry that we may not be able to fix it before Fedora 17 is end of life. If you would still like to see this bug fixed and are able to reproduce it against a later version of Fedora, you are encouraged change the 'version' to a later Fedora version prior to Fedora 17's end of life. Although we aim to fix as many bugs as possible during every release's lifetime, sometimes those efforts are overtaken by events. Often a more recent Fedora release includes newer upstream software that fixes bugs or makes them obsolete.
Fedora 17 changed to end-of-life (EOL) status on 2013-07-30. Fedora 17 is no longer maintained, which means that it will not receive any further security or bug fix updates. As a result we are closing this bug. If you can reproduce this bug against a currently maintained version of Fedora please feel free to reopen this bug against that version. Thank you for reporting this bug and we are sorry it could not be fixed.