Hi,
Yesterday I spent several hours trying to understand why this libtool
invocation:
/bin/sh ../libtool --tag=CC --mode=link
/Users/runner/work/ci-scratch/ci-scratch/macos-compile clang -g -O2
-no-undefined -version-info 0:0:0 -rpath /usr/local/lib -L/Users/runner/lib -o
libintl_m2.la -rpath /usr/local/lib Libintl.lo ../intl/libintl.la
/opt/homebrew/Cellar/gcc/14.2.0_1/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/14/../../../libm2pim.dylib
results in libtool (version 2.5.4, on macOS) emitting this output
libtool: link: /Users/runner/work/ci-scratch/ci-scratch/macos-compile clang
-dynamiclib -o .libs/libintl_m2.0.dylib .libs/Libintl.o -L/Users/runner/lib
../intl/.libs/libintl.dylib -lpthread -g -O2 -install_name
/usr/local/lib/libintl_m2.0.dylib -compatibility_version 1 -current_version 1.0
It lacks the dependency to .../libm2pim.dylib, and thus produces link
errors for symbols that are in fact provided by libm2pim.dylib:
Undefined symbols for architecture arm64:
"_m2pim_DynamicStrings_InitStringCharStar", referenced from:
_Libintl_Gettext in Libintl.o
_Libintl_DGettext in Libintl.o
_Libintl_DCGettext in Libintl.o
_Libintl_NGettext in Libintl.o
_Libintl_DNGettext in Libintl.o
_Libintl_DCNGettext in Libintl.o
"_m2pim_M2RTS_RegisterModule", referenced from:
__M2_Libintl_ctor in Libintl.o
"_m2pim_M2RTS_RequestDependant", referenced from:
__M2_Libintl_dep in Libintl.o
__M2_Libintl_dep in Libintl.o
__M2_Libintl_dep in Libintl.o
__M2_Libintl_dep in Libintl.o
__M2_Libintl_dep in Libintl.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [libintl_m2.la] Error 1
Ideally, libtool would produce an error message:
link dependencies cannot be given directly as arguments:
/opt/homebrew/Cellar/gcc/14.2.0_1/bin/../lib/gcc/current/gcc/aarch64-apple-darwin24/14/../../../libm2pim.dylib
But barring such a change, here's at least a documentation fix, to make users
like me aware of what the problem is.
>From f71eaf2dbbdfb7ed4f874251705719addc304e72 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Tue, 6 May 2025 17:00:51 +0200
Subject: [PATCH] doc: Explain how to specify library dependencies.
* doc/libtool.texi (Link mode): Explain how to specify dependencies to
already installed libraries.
---
doc/libtool.texi | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/doc/libtool.texi b/doc/libtool.texi
index 60ddab7a..ba64245e 100644
--- a/doc/libtool.texi
+++ b/doc/libtool.texi
@@ -1708,6 +1708,11 @@ Pass a linker-specific flag directly to the linker.
Pass a link-specific flag to the compiler driver (@code{CC}) during linking.
@end table
+Note: When the output file shall depend on an installed library, you
+cannot specify the library name as @code{@var{dir}/lib@var{name}.a} or
+@code{@var{dir}/lib@var{name}.so} as part of the @var{mode-args}.
+Instead, pass the arguments @code{-L@var{dir}} and @code{-l@var{name}}.
+
If the @var{output-file} ends in @file{.la}, then a libtool library is
created, which must be built only from library objects (@file{.lo} files).
The @option{-rpath} option is required. In the current implementation,
--
2.43.0