[perl] Portably linking to libstdc++

Sisyphus sisyphus1@optusnet.com.au
Mon Oct 20 06:55:00 GMT 2008


----- Original Message ----- 
From: "Brian Dessent" <brian@dessent.net>
>> But on cygwin, there is no '-lstdc++' to be found in $Config{libpth}, so
>> MakeMaker decides to not pass the switch on (which has always been
>> MakeMaker's policy in such cases, afaik). This is a pity - there would be 
>> no
>> problem if it *did* the pass switch on, as both gcc and g++ on cygwin 
>> will
>> resolve that link.
>
> MakeMaker should be fixed to allow the switch through.
>

This has been a long standing feature of MakeMaker, and I expect that a 
significant number of modules would be broken if that behaviour was changed. 
It allows module authors the convenience of being able to specify all libs 
that might be needed, without having to worry about the fact that some of 
those libs will be both unneeded and absent on some systems. At least, I 
*guess* that's the idea behind it.
It would be better, however, if there was some way to override that 
behaviour and force MakeMaker to pass the switch on. (I don't think such a 
facility exists ... but I couldn't say for sure ...)

>
> 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++'.
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':

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

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

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').

Thanks for the reply, Brian.

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