]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
ltmain.in: Recognise explicit shared library args
authorNicolas Boulenguez <nicolas@debian.org>
Mon, 23 Feb 2026 16:32:35 +0000 (17:32 +0100)
committerIleana Dumitrescu <ileanadumitrescu95@gmail.com>
Wed, 22 Apr 2026 17:14:19 +0000 (20:14 +0300)
When linking a program, GNU Libtool recognises libfoo.so arguments, but
it does not when linking shared libraries. Now, libfoo.so will be
equivalent to linking with -l:libfoo.so or -lfoo.

Reported: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=54726

* build-aux/ltmain.in: Link an explicit shared library.
* Makefile.am: Add new test file, deplib-path.at.
* tests/deplib-path.at: Add new test for shared linking deplibs by the
  libN.so name.
* NEWS: Update.

Makefile.am
NEWS
build-aux/ltmain.in
tests/deplib-path.at [new file with mode: 0644]

index 02d80926a5f98aa6041051595e3cc5fdcaf55148..52e00476d378139b1dbc68ea1287312e41585856 100644 (file)
@@ -693,6 +693,7 @@ TESTSUITE_AT        = tests/testsuite.at \
                  tests/execute-mode.at \
                  tests/bindir.at \
                  tests/cwrapper.at \
+                 tests/deplib-path.at \
                  tests/deplib-in-subdir.at \
                  tests/infer-tag.at \
                  tests/localization.at \
diff --git a/NEWS b/NEWS
index 098b781af50d3a7017d5edef6cd5a4ea5ee5c617..a3a2321cdbafd818b0ed8ac59905412e9b961c82 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ NEWS - list of user-visible changes between releases of GNU Libtool
 
   - Pass 'resource-dir=*' flag for Clang.
 
+  - Recognise explicit shared library arguments when linking dependency
+    libraries to a shared library, like exists when linking a program.
+
 ** Bug fixes:
 
   - Store cygpath file path conversions correctly for MSYS2 and MSVC.
index 9108006cf228e6b2f5a6fb284fbdb51e88d3eaef..df85f00b0fcc6f668c28ff43a33eccc8c9c7521c 100644 (file)
@@ -5795,8 +5795,8 @@ func_mode_link ()
        fi
        ;;
 
-      *.$libext)
-       # An archive.
+      *.$libext|*.so)
+       # An archive or an explicit shared library.
        func_append deplibs " $arg"
        func_append old_deplibs " $arg"
        continue
@@ -6174,6 +6174,25 @@ func_mode_link ()
          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"
diff --git a/tests/deplib-path.at b/tests/deplib-path.at
new file mode 100644 (file)
index 0000000..0b2df15
--- /dev/null
@@ -0,0 +1,89 @@
+# deplib-path.at -- test shared linking deplibs by libN.so name -*- 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/>.
+####
+
+# Ensures libN.so -l:libN.so -lN are equivalent
+
+AT_SETUP([shared linking deplibs by libN.so name])
+
+case $host_os in
+linux*) ;;
+*) noskip=false ;;
+esac
+
+AT_CHECK([$noskip || (exit 77)])
+
+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 = -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