[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lib-ignore: link error with Sun C++ compiler
From: |
Bruno Haible |
Subject: |
Re: lib-ignore: link error with Sun C++ compiler |
Date: |
Sat, 20 Mar 2010 23:52:25 +0100 |
User-agent: |
KMail/1.9.9 |
Hello Ralf,
> > 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)
> ...
> you might want to make the macro callable more than once, with different
> language set, similar to how AC_OPENMP works; then, the user can add
>
> CXX_IGNORE_UNUSED_LIBS to CXXFLAGS (or CXXLINK)
> CC_IGNORE_UNUSED_LIBS to CFLAGS
Here's a proposed patch. I've tested that on a glibc system it yields
checking for C compiler flag to ignore unused libraries... -Wl,--as-needed
checking for C++ compiler flag to ignore unused libraries... -Wl,--as-needed
and with a Solaris toolchain:
checking for C compiler flag to ignore unused libraries... -Wl,-z,ignore
checking for C++ compiler flag to ignore unused libraries... -Qoption ld
-z,ignore
Just as it should be.
2010-03-20 Bruno Haible <address@hidden>
lib-ignore: Determine different options for different compilers.
* m4/lib-ignore.m4 (gl_IGNORE_UNUSED_LIBRARIES): Set a variable which
depends on the current language (C/C++/Fortran). Don't set LDFLAGS.
Add comments.
(_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS): New macro.
* NEWS: Mention the change.
--- NEWS.orig Sat Mar 20 23:50:42 2010
+++ NEWS Sat Mar 20 23:50:31 2010
@@ -6,6 +6,12 @@
Date Modules Changes
+2010-03-20 lib-ignore This module now provides a variable
+ IGNORE_UNUSED_LIBRARIES_CFLAGS that you should
+ add to LDFLAGS (when linking C programs only) or
+ CFLAGS yourself. It is no longer added to LDFLAGS
+ automatically.
+
2010-03-18 pty This module now only declares the pty.h header.
Use the new modules 'forkpty' or 'openpty' to
get the functions that were previously provided.
--- m4/lib-ignore.m4.orig Sat Mar 20 23:50:42 2010
+++ m4/lib-ignore.m4 Sat Mar 20 23:38:01 2010
@@ -7,11 +7,44 @@
dnl Written by Paul Eggert.
+# gl_IGNORE_UNUSED_LIBRARIES
+# --------------------------
+# Determines the option to be passed to the C/C++/Fortran 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++ and Sun Fortran like '-Qoption ld -z,ignore'.
+# '-Wl,-z,ignore' is not accepted.
+# '-z ignore' is accepted but has no effect.
+#
+# Sets and substitutes a variable that depends on the current language:
+# - IGNORE_UNUSED_LIBRARIES_CFLAGS for C
+# - IGNORE_UNUSED_LIBRARIES_CXXFLAGS for C++
+# - IGNORE_UNUSED_LIBRARIES_FFLAGS for Fortran
+#
AC_DEFUN([gl_IGNORE_UNUSED_LIBRARIES],
[
- AC_CACHE_CHECK([for flag to ignore unused libraries],
- [gl_cv_ignore_unused_libraries],
- [gl_cv_ignore_unused_libraries=none
+ AC_CACHE_CHECK([for []_AC_LANG[] compiler flag to ignore unused libraries],
+ [gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries],
+ [gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries=none
gl_saved_ldflags=$LDFLAGS
gl_saved_libs=$LIBS
# Link with -lm to detect binutils 2.16 bug with --as-needed; see
@@ -21,23 +54,57 @@
# 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.
- for gl_flags in \
- '-Wl,--as-needed' \
- '-Wl,-z,ignore' \
- '-z ignore'
+ for gl_flags in _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS
do
LDFLAGS="$gl_flags $LDFLAGS"
AC_LINK_IFELSE([AC_LANG_PROGRAM()],
- [gl_cv_ignore_unused_libraries=$gl_flags])
+ [gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries=$gl_flags])
LDFLAGS=$gl_saved_ldflags
- test "$gl_cv_ignore_unused_libraries" != none && break
+ test "$gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries" != none
&&
+ break
done
- LIBS=$gl_saved_libs])
+ LIBS=$gl_saved_libs
+ ])
+ IGNORE_UNUSED_LIBRARIES_[]_AC_LANG_PREFIX[]FLAGS=
+ if test "$gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries" != none;
then
+
IGNORE_UNUSED_LIBRARIES_[]_AC_LANG_PREFIX[]FLAGS="$gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries"
+ fi
+ AC_SUBST([IGNORE_UNUSED_LIBRARIES_]_AC_LANG_PREFIX[FLAGS])
+])
+
+# _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS
+# -----------------------------------
+# Expands to the language dependent options to be tried.
+AC_DEFUN([_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS],
+[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
+
+# _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(C)
+# --------------------------------------
+m4_define([_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(C)],
+[ '-Wl,--as-needed' \
+ '-Wl,-z,ignore' \
+ '-z ignore'
+])
- test "$gl_cv_ignore_unused_libraries" != none &&
- LDFLAGS="$LDFLAGS $gl_cv_ignore_unused_libraries"
+# _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(C++)
+# ----------------------------------------
+m4_define([_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(C++)],
+[ '-Wl,--as-needed' \
+ '-Qoption ld -z,ignore' \
+ '-Wl,-z,ignore' \
+ '-z ignore'
])
+
+# _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(Fortran 77)
+# -----------------------------------------------
+m4_copy([_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(C++)],
+ [_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(Fortran 77)])
+
+# _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(Fortran)
+# --------------------------------------------
+m4_copy([_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(Fortran 77)],
+ [_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(Fortran)])
- lib-ignore: link error with Sun C++ compiler, Bruno Haible, 2010/03/07
- Re: lib-ignore: link error with Sun C++ compiler, Ralf Wildenhues, 2010/03/08
- Re: lib-ignore: link error with Sun C++ compiler, Bruno Haible, 2010/03/14
- Re: lib-ignore: link error with Sun C++ compiler, Ralf Wildenhues, 2010/03/15
- Re: lib-ignore: link error with Sun C++ compiler,
Bruno Haible <=
- Re: lib-ignore: link error with Sun C++ compiler, Ralf Wildenhues, 2010/03/21
- Re: lib-ignore: link error with Sun C++ compiler, Bruno Haible, 2010/03/21
- Re: lib-ignore: link error with Sun C++ compiler, Bruno Haible, 2010/03/28
- Re: lib-ignore: link error with Sun C++ compiler, Jim Meyering, 2010/03/29