g-i-scanner: sometimes links with -Wl,--as-needed despite attempts to do otherwise
Minimal reproducer: this requires libtool at /usr/bin/libtool
, for example from Debian's libtool
package.
all: Test-0.gir
clean:
rm -f libtest.so libtest.so.0 Test-0.gir libtest.c libtest.h
libtest.h: Makefile
echo "int test_answer(void);" > $@
libtest.c: Makefile
echo "int test_answer(void) { return 42; }" > $@
libtest.so: Makefile libtest.c libtest.h
$(CC) -shared -Wl,-soname,libtest.so.0 -olibtest.so.0 libtest.c
ln -fns libtest.so.0 $@
Test-0.gir: libtest.so Makefile libtest.c libtest.h
g-ir-scanner --libtool=/usr/bin/libtool --warn-all -o$@ -L. -ltest -nTest --nsversion=0 libtest.h libtest.c
tail -v -n+0 $@
Put this in Makefile in an otherwise empty directory, and run LDFLAGS=-Wl,--as-needed make
. If your toolchain defaults to -Wl,--as-needed
(like Debian 12's) then you might not need the LDFLAGS
.
Expected result: I get a GIR XML binding for libtest.so
with shared-library="libtest.so.0"
describing <function name="answer" c:identifier="test_answer">
.
Actual result (on Debian testing/unstable, gobject-introspection 1.80.1-2):
echo "int test_answer(void) { return 42; }" > libtest.c
echo "int test_answer(void);" > libtest.h
cc -shared -Wl,-soname,libtest.so.0 -olibtest.so.0 libtest.c
ln -fns libtest.so.0 libtest.so
g-ir-scanner --libtool=/usr/bin/libtool --warn-all -oTest-0.gir -L. -ltest -nTest --nsversion=0 libtest.h libtest.c
g-ir-scanner: link: /usr/bin/libtool --mode=link --tag=CC x86_64-linux-gnu-gcc -o /home/smcv/src/debian/qa/_build/t/tmp-introspectrs9uss8j/Test-0 -export-dynamic /home/smcv/src/debian/qa/_build/t/tmp-introspectrs9uss8j/Test-0.o -L. -L. -ltest -lgio-2.0 -lgobject-2.0 -Wl,--export-dynamic -lgmodule-2.0 -pthread -lglib-2.0 -lglib-2.0
libtool: link: x86_64-linux-gnu-gcc -o /home/smcv/src/debian/qa/_build/t/tmp-introspectrs9uss8j/Test-0 /home/smcv/src/debian/qa/_build/t/tmp-introspectrs9uss8j/Test-0.o -Wl,--export-dynamic -Wl,--export-dynamic -L. -ltest -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -pthread
ERROR: can't resolve libraries to shared libraries: test
make: *** [Makefile:17: Test-0.gir] Error 1
This is because libtest
doesn't contain any get_type()
or similar functions, so the dumper has no requirement for a link-time reference to it, so -Wl,--as-needed
discards the -ltest
instead of generating a DT_NEEDED
header.
Fix proposed in !463.