https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87182
--- Comment #5 from Stefan Vigerske <vigerske at math dot hu-berlin.de> --- The AC_CHECK_LIB([z], [compress], []) adds -lz to the LIBS variable in the Makefile, if successful. This results in calling the libtool that builds libbacktrace.la with -lz, which then results in having dependency_libs=' -lz' in libbacktrace.la. The build of libgfortran(.so) picks this up, so that the systems libz.so ends up as dependency of libgfortran.so. If libbacktrace itself does not require zlib, then maybe -lz should not end up in LIBS. I don't know what the preferred way to handle this is. One way is to save LIBS before calling AC_CHECK_LIB and to restore it again afterwards. However, the test executable would still need -lz.