bug#54726: when linking a shared library on Linux, libtool ignores libfoo.so arguments
Nicolas Boulenguez <[email protected]> Mon, 23 Feb 2026 17:32:35 +0100
| Newsgroups | gmane.comp.gnu.libtool.bugs |
|---|---|
| Message-ID | <aZyBI_K1-ZB0CP7d@pegase> |
https://lists.gnu.org/archive/html/bug-libtool/2022-04/msg00000.html
(bug#54726 does not public anymore)
> > When linking a shared library or a program against a (locally built, not
> > installed) foo library, it is recommended to prefer
> > dir/libfoo.so
> > over
> > -Ldir -lfoo
> > which only adds complexity and unwanted ambiguity (for example,
> > /usr/lib/libfoo.{a,so} may silently be selected if dir/libfoo.so is
> > unexpectedly missing).
> > Libtool recognizes such options when linking a program, but ignores
> > them when linking a shared library.
Hello.
Here is a new test,
currently failing because the 'one' symbol is not found,
passing with the changes in ltmain.in.
Tested with GNU libtool 2.4.6 and 2.5.4 on Debian/GNU Linux x86_64.
The test should be skipped on platforms without .so.
The patch imitates the existing code and is probably incomplete.
--- a/Makefile.am
+++ b/Makefile.am
@@ -728,6 +728,7 @@
tests/bug_62343.at \
tests/bug_71489.at \
tests/bug_42313.at \
+ tests/deplib-path.at \
$(NOTHING_ELSE)
EXTRA_DIST += $(testsuite) $(TESTSUITE_AT) $(package_m4)
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -5703,8 +5703,8 @@
fi
;;
- *.$libext)
- # An archive.
+ *.$libext|*.so)
+ # An archive or an explicit shared library.
func_append deplibs " $arg"
func_append old_deplibs " $arg"
continue
@@ -6076,6 +6076,25 @@
func_resolve_sysroot "$deplib"
lib=$func_resolve_sysroot_result
;;
+ *.so)
+ case $linkmode,$pass in
+ lib,*)
+ deplibs="$deplib $deplibs"
+ newdependency_libs="$deplib $newdependency_libs"
+ ;;
+ prog,link)
+ compile_deplibs="$deplib $compile_deplibs"
+ finalize_deplibs="$deplib $finalize_deplibs"
+ ;;
+ prog,*)
+ deplibs="$deplib $deplibs"
+ ;;
+ *)
+ func_warning "'$deplib' is ignored for archives/objects"
+ ;;
+ esac
+ continue
+ ;;
*.$libext)
if test conv = "$pass"; then
deplibs="$deplib $deplibs"
--- /dev/null
+++ b/tests/deplib-path.at
@@ -0,0 +1,82 @@
+# deplib-path.at -- test libN.so -l:libN.so -lN are equivalent -*- Autotest -*-
+#
+# Copyright (C) 2020-2026 Free Software Foundation, Inc.
+# Written by Nicolas Boulenguez, 2020-2026
+#
+# This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# GNU Libtool is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool. If not, see <https://www.gnu.org/licenses/>.
+####
+
+AT_SETUP([libN.so -l:libN.so -lN are equivalent])
+
+AT_DATA([one.c],
+[[
+int one(void) { return 1; }
+]])
+
+AT_DATA([two.c],
+[[
+int two(void) { return 2; }
+]])
+
+AT_DATA([three.c],
+[[
+int three(void) { return 3; }
+]])
+
+AT_DATA([sum.c],
+[[
+extern int one(void);
+extern int two(void);
+extern int three(void);
+int sum(void) { return one()+two()+three(); }
+]])
+
+AT_DATA([configure.ac],
+[[
+AC_INIT([deplib-path], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_MACRO_DIR([m4])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+LT_INIT
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+]])
+
+AT_DATA([Makefile.am],
+[[
+AUTOMAKE_OPTIONS = no-dependencies foreign
+ACLOCAL_AMFLAGS = -I m4
+AM_LDFLAGS = -Wl,--no-undefined
+lib_LTLIBRARIES = libsum.la
+libsum_la_SOURCES = sum.c
+libsum_la_LIBADD = libone.so -L. -l:libtwo.so -lthree
+EXTRA_libsum_la_DEPENDENCIES = libtwo.so libthree.so
+libone.so libtwo.so libthree.so: CFLAGS += -fPIC
+libone.so libtwo.so libthree.so: lib%.so: %.o
+ $(LINK.c) -shared -o $@ $^
+]])
+
+LT_AT_LIBTOOLIZE
+LT_AT_ACLOCAL([-I m4])
+LT_AT_AUTOMAKE([--add-missing])
+LT_AT_AUTOCONF
+LT_AT_CONFIGURE
+LT_AT_MAKE
+
+AT_CLEANUP