-
Notifications
You must be signed in to change notification settings - Fork 10
Description
ExtUtils::CppGuess version 0.26
Perl 5.34
Debian 11
I have a simple XS wrapper around : an Alien module
The wrapper uses Dist::Zilla with the following XS related stanzas:
[PPPort]
[MakeMaker::Awesome]
header = use Alien::Base::Wrapper qw( CXC::Alien::XTime !export );
header = use ExtUtils::CppGuess;
WriteMakefile_arg = Alien::Base::Wrapper->mm_args
WriteMakefile_arg = ExtUtils::CppGuess->new->makemaker_options
The problem arises in linking against the static Alien library. The link line looks fine:
cc -L/home/dj/Work/Chandra-Time/local/lib/perl5/x86_64-linux/auto/share/dist/CXC-Alien-XTime/lib -shared -O2 -L/usr/local/lib -fstack-protector-strong Time.o -lstdc++ -o blib/arch/auto/Chandra/Time/Time.so \
-L/home/dj/Work/Chandra-Time/local/lib/perl5/x86_64-linux/auto/share/dist/CXC-Alien-XTime/lib -lXTime \
but running the Perl test code results in:
Can't load '/home/dj/Work/Chandra-Time/Chandra-Time-0.10/blib/arch/auto/Chandra/Time/Time.so' for module Chandra::Time: /home/dj/Work/Chandra-Time/Chandra-Time-0.10/blib/arch/auto/Chandra/Time/Time.so: undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE at /home/dj/.plenv/versions/5.34/lib/perl5/5.34.1/x86_64-linux/DynaLoader.pm line 193.
Manually relinking with the Wl,--no-undefined
cc -Wl,--no-undefined -L/home/dj/Work/Chandra-Time/local/lib/perl5/x86_64-linux/auto/share/dist/CXC-Alien-XTime/lib -shared -O2 -L/usr/local/lib -fstack-protector-strong Time.o -lstdc++ -o blib/arch/auto/Chandra/Time/Time.so -L/home/dj/Work/Chandra-Time/local/lib/perl5/x86_64-linux/auto/share/dist/CXC-Alien-XTime/lib -lXTime
provides some insight, spewing forth lots of undefined references to C++ std library symbols. But, there's definitely a -lstdc++ on the link line, so what gives? Unfortunately, it's before the link against the libXTime library, so it isn't used to resolve any symbols in objects which appear after it on the command line.
From TF (ld) M,
Normally, an archive is searched only once in the order that it is specified on the command line. If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on the command line, the linker would not be able to resolve that reference.
Moving the -lstdc++ to the end of the link line solves all of the problems. Unfortunately, the hook that ExtUtils::CppGuess uses to insert -lstdc++ doesn't provide that flexibility.
I tried using ld's --start-group / --end-group options, but that works only if all of the libraries are in the same group, e.g.
-Wl,--start-group -lstdc++ -lXTime -Wl,--end-group
which isn't possible. using the OTHERLDFLAGS hook that ExtUtils::CppGuess uses.
Any ideas on how to approach this?
Thanks!
Diab