[perl] Portably linking to libstdc++
Sisyphus
sisyphus1@optusnet.com.au
Mon Oct 20 12:50:00 GMT 2008
----- Original Message -----
From: "Brian Dessent" <brian@dessent.net>
.
.
>
> Please post the entire link command and not just the error. It's
> impossible to say what the true nature of the problem is otherwise. For
> example, if you're trying to link a library and not an executable then
> the above error would be due to missing the "-shared" flag.
For the failure in question (ie the WinMain error), I start by running 'perl
Makefile.PL LD="g++"'.
This means that both CC and LD have been set to g++. The failing link
command is:
###################################
g++ -s -L/usr/local/lib Size.o -o blib/arch/auto/Devel/Size/Size.dll \
/usr/lib/perl5/5.8/cygwin/CORE/libperl.dll.a \
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(libcmain.o):(.text+0xab):
undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status
make: *** [blib/arch/auto/Devel/Size/Size.dll] Error 1
###################################
If I start by running simply 'perl Makefile.PL', then CC is set to g++, but
LD is set to ld2 (gcc).
The error is:
###################################
ld2 -s -L/usr/local/lib Size.o -o blib/arch/auto/Devel/Size/Size.dll \
/usr/lib/perl5/5.8/cygwin/CORE/libperl.dll.a \
gcc -shared -o
Size.dll -Wl,--out-implib=libSize.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import
-Wl,--stack,8388608 -Wl,--enable-auto-image-base -s -L/usr/local/lib Size.o
/usr/lib/perl5/5.8/cygwin/CORE/libperl.dll.a
Size.o:Size.c:(.text+0x122): undefined reference to `___gxx_personality_sj0'
Size.o:Size.c:(.text+0x21b): undefined reference to `___cxa_begin_catch'
Size.o:Size.c:(.text+0x24b): undefined reference to `___cxa_end_catch'
[followed by more undefined references to the same symbols]
###################################
If I start by running 'perl Makefile.PL LIBS="-lstdc++"', then everything
proceeds fine - but only because I've hacked $Config{libpth} to include the
location of libstdc++.a. The same section of the build output is:
###################################
ld2 -s -L/usr/local/lib Size.o -o blib/arch/auto/Devel/Size/Size.dll \
/usr/lib/perl5/5.8/cygwin/CORE/libperl.dll.a -lstdc++ \
gcc -shared -o
Size.dll -Wl,--out-implib=libSize.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import
-Wl,--stack,8388608 -Wl,--enable-auto-image-base \
-s -L/usr/local/lib Size.o
/usr/lib/perl5/5.8/cygwin/CORE/libperl.dll.a -lstdc++
Creating library file: libSize.dll.a
mv Size.dll libSize.dll.a blib/arch/auto/Devel/Size/
chmod 755 blib/arch/auto/Devel/Size/Size.dll
cp Size.bs blib/arch/auto/Devel/Size/Size.bs
chmod 644 blib/arch/auto/Devel/Size/Size.bs
/usr/bin/perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(0,
'blib/lib', 'blib/arch')" t/*.t
t/basic......ok
t/pod........ok
t/pod_cov....ok
t/recurse....ok
All tests successful.
Files=4, Tests=69, 2 wallclock secs ( 0.93 cusr + 0.73 csys = 1.66 CPU)
###################################
But you're right, of course, about the missing "-shared" being a (the?)
problem. If I start with 'perl Makefile.PL LD="g++ -shared"' then everything
works fine:
###################################
g++ -shared -s -L/usr/local/lib Size.o -o
blib/arch/auto/Devel/Size/Size.dll \
/usr/lib/perl5/5.8/cygwin/CORE/libperl.dll.a \
chmod 755 blib/arch/auto/Devel/Size/Size.dll
cp Size.bs blib/arch/auto/Devel/Size/Size.bs
chmod 644 blib/arch/auto/Devel/Size/Size.bs
/usr/bin/perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(0,
'blib/lib', 'blib/arch')" t/*.t
t/basic......ok
t/pod........ok
t/pod_cov....ok
t/recurse....ok
All tests successful.
Files=4, Tests=69, 3 wallclock secs ( 0.93 cusr + 0.79 csys = 1.72 CPU)
###################################
Apparently g++ needs a "-shared" but ld2 doesn't. (I don't understand that.)
And I don't understand what is achieved by:
gcc -shared -o
Size.dll -Wl,--out-implib=libSize.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import
-Wl,--stack,8388608 -Wl,--enable-auto-image-base \
-s -L/usr/local/lib Size.o /usr/lib/perl5/5.8/cygwin/CORE/libperl.dll.a
That command gets run only if LD is ld2 - there doesn't seem to be a
comparable command if LD is set to either "g++" or "g++ -shared".
Cheers,
Rob
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list