Source: libtool
Version: 2.4.6-14
Severity: normal

Hello.

When linking a shared library against another uninstalled shared
library missing libtool support,
      -L. -lfoo      -L. -l:libfoo.so      libfoo.so
should be equivalent.

https://www.gnu.org/software/libtool/manual/libtool.html#FOOT2 and
https://www.gnu.org/software/automake/manual/automake.html#Linking
both recommend the third form because it is less ambiguous, but
libtool ignores it.

This results in the library containing undefined symbols, or an
immediate failure with --no-undefined.

A reproducer is attached.
#!/bin/sh
set -Cefu

cat > indirect.c <<EOF
#include <stdio.h>
void indirect (void) {
  printf ("If you are reading this, all probably went OK.\n");
}
EOF

cat > direct.c <<EOF
void indirect (void);
void direct (void) {
  indirect ();
}
EOF
cat > main.c <<EOF
void direct (void);
int main (void) {
  direct ();
  return 0;
}
EOF

cat > configure.ac <<EOF
AC_INIT([foo], [0.0.0])
AM_INIT_AUTOMAKE([foreign])
LT_INIT
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
EOF

cat > Makefile.am <<EOF
bin_PROGRAMS = main
main_SOURCES = main.c
main_LDADD = libdirect.la
main_LDFLAGS = -Wl,-rpath-link=.

lib_LTLIBRARIES = libdirect.la
libdirect_la_SOURCES = direct.c
# This fails:
libdirect_la_LIBADD = libindirect.so
# This works:
# libdirect_la_LIBADD = -L. -l:libindirect.so
# EXTRA_libdirect_la_DEPENDENCIES = ./libindirect.so

# For unrelated reasons, libindirect is unable to use libtool.
libindirect.so: CFLAGS += -fPIC
libindirect.so: indirect.o
        \$(LINK.c) -shared -o \$@ \$^
EOF

autoreconf -i
./configure
# --no-undefined forces the script to stop at the interesting lines.
# Without it, libtool would fail later when trying to link main.o.
make LDFLAGS=-Wl,--no-undefined
LD_LIBRARY_PATH=. ./main

Reply via email to