[perl] Portably linking to libstdc++

Reini Urban rurban@x-ray.at
Mon Oct 20 07:32:00 GMT 2008


2008/10/20 Sisyphus:
>> Really the correct way to link C++ code is by using g++ which doesn't
>> require this manual -lstdc++ nonsense.  Can't you just do that, by
>> either fixing the makefile to link with $(CXX) or overriding the
>> appropriate variable?

> Aaah ... good point. I had missed something.
>
> I had changed $Config{cc} from 'gcc' to 'g++' thinking that should do the
> trick. And it works fine for MinGW-built perls .... but (as it turns out)
> only because $Config{ld} is already set to 'g++'.

LD is already g++. And if you need to compile C++ you have to use g++
anyway as CC.
No need to change anything in current cygwin perl IMO.

> On both linux and cygwin, I've just realised that $Config{ld} is still set
> to 'gcc' - which is what necessitates linking explicitly to libstdc++.
> Of course, the other option on both linux and cygwin is to set *both*
> $Config{cc} and $Config{ld} to 'g++', and that works fine on linux, but
> doesn't quite work on cygwin where I still get an undefined reference to
> `_WinMain@16':

Current cygwin perl already has g++ as LD for some releases.

> /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
>
> Why does that happen ?

Maybe because the linker believes you have a -mwindows GUI app?
Which distro are you talking about?
InlineX::CPP2XS I assume.

> Btw, overriding $Config{cc} and $Config{ld} is trivial. In the Makefile.PL's
> %WriteMakefile() it's just a matter of:
>
>  CC => 'g++',
>  LD => 'g++',
>
> Or they can be overridden from the command line when the Makefile.PL is run:
>
>  perl Makefile.PL CC="g++" LD="g++"

  perl Makefile.PL CC="g++"
should be enough.

> And I think that's all I need do on any perl build where g++ is the name of
> the c++ compiler .... except for Cygwin (where it doesn't work because of
> that undefined reference to `_WinMain@16').
-- 
Reini Urban
http://phpwiki.org/              http://murbreak.at/

--
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