Ralf Wildenhues wrote: > > The reason is that the flag -Wl,-z,ignore is accepted by the C compiler > > (cc), but > > leads to an error with the C++ compiler (CC). > > Sun CC needs '-Qoption ld ' as prefix to linker flags (mind the trailing > space) rather than '-Wl,'.
Thanks for this info. So, a possible first step is to update the comments in lib-ignore.m4, like in the proposed patch below. But this does not fix the problem with coreutils, as long as it has some source files in C++. I would therefore find it useful to change lib-ignore.m4 so that it sets an AC_SUBSTed variable IGNORE_UNUSED_LIBS, and coreutils/Makefile.am can then do AM_LDFLAGS = $(IGNORE_UNUSED_LIBS) What do you think? Bruno 2010-03-14 Bruno Haible <br...@clisp.org> * m4/lib-ignore.m4 (gl_IGNORE_UNUSED_LIBRARIES): Add comments. --- m4/lib-ignore.m4.orig Sun Mar 14 17:06:37 2010 +++ m4/lib-ignore.m4 Sun Mar 14 16:20:31 2010 @@ -9,6 +9,30 @@ AC_DEFUN([gl_IGNORE_UNUSED_LIBRARIES], [ + # Determines the option to be passed to the C compiler, so that it + # omits unused libraries. + # Example (on Solaris): + # $ cc foo.c -lnsl; ldd ./a.out + # libnsl.so.1 => /lib/libnsl.so.1 + # libc.so.1 => /lib/libc.so.1 + # libmp.so.2 => /lib/libmp.so.2 + # libmd.so.1 => /lib/libmd.so.1 + # libscf.so.1 => /lib/libscf.so.1 + # libdoor.so.1 => /lib/libdoor.so.1 + # libuutil.so.1 => /lib/libuutil.so.1 + # libgen.so.1 => /lib/libgen.so.1 + # libm.so.2 => /lib/libm.so.2 + # $ cc foo.c -lnsl -Wl,-z,ignore; ldd ./a.out + # libc.so.1 => /lib/libc.so.1 + # libm.so.2 => /lib/libm.so.2 + + # Note that the options works only for the C compiler, not for the C++ + # compiler: + # - Sun C likes '-Wl,-z,ignore'. '-Qoption ld -z,ignore' is not accepted. + # '-z ignore' is accepted but has no effect. + # - Sun C++ likes '-Qoption ld -z,ignore'. '-Wl,-z,ignore' is not accepted. + # '-z ignore' is accepted but has no effect. + AC_CACHE_CHECK([for flag to ignore unused libraries], [gl_cv_ignore_unused_libraries], [gl_cv_ignore_unused_libraries=none @@ -21,7 +45,7 @@ # to forestall problems with linkers that have -z, -i, -g, -n, etc. flags. # GCC + binutils likes '-Wl,--as-needed'. # GCC + Solaris ld likes '-Wl,-z,ignore'. - # Sun C likes '-z ignore'. + # Sun C likes '-Wl,-z,ignore'. '-z ignore' is accepted but has no effect. # Don't try bare '--as-needed'; nothing likes it and the HP-UX 11.11 # native cc issues annoying warnings and then ignores it, # which would cause us to incorrectly conclude that it worked. @@ -38,6 +62,8 @@ done LIBS=$gl_saved_libs]) + # Note that adding this options to LDFLAGS unconditionally does not work in + # projects that are partially in C++. test "$gl_cv_ignore_unused_libraries" != none && LDFLAGS="$LDFLAGS $gl_cv_ignore_unused_libraries" ])