X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Message-ID: <362AEC237F86449F9A0FDD5F0198E068@desktop2> From: "Sisyphus" To: References: <586E6C4720134D06B35A67112D3BBBCE AT desktop2> <48FB462B DOT 4B75336B AT dessent DOT net> <48FC5562 DOT 1DDA1FAE AT dessent DOT net> In-Reply-To: <48FC5562.1DDA1FAE@dessent.net> Subject: Re: [perl] Portably linking to libstdc++ Date: Mon, 20 Oct 2008 23:48:10 +1100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Windows Mail 6.0.6001.18000 X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com ----- Original Message ----- From: "Brian Dessent" . . > > 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 AT 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/