Avner has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm building a Perl extension (dll in Windows XP) using ExtUtils::MakeMaker. This dll needs to link with other libraries that were built in static mode (-MTd). My perl configuration states dynamic libraries (-MD) which causes MakeMaker to pull a dynamic C library (msvcrtd.dll). The other libraries are using the static C library (libcmtd.lib) These dynamic and static C libraries collide giving link errors. Is there a way to force perl to compile with (-MTd) albeit its configuration flags? I tried reinstalling Perl (ActiveState perl v5.8.8 built for MSWin32-x86-multi-thread) but didn't see an option to control the configuration flags. Also, my platform supports both dynamic (-MD) and static (-MTd) builds. Does this mean that I have to maintain two versions of Perl? Thanks, Avner
  • Comment on Perl MakeMaker - how to force Perl linking with the static C library (libcrt.lib) instead of dynamic C library (msvcrt.lib)

Replies are listed 'Best First'.
Re: Perl MakeMaker - how to force Perl linking with the static C library (libcrt.lib) instead of dynamic C library (msvcrt.lib)
by Corion (Patriarch) on Apr 17, 2007 at 20:54 UTC

    You can force the compiler settings Perl and ExtUtils::MakeMaker use by editing Config.pm. But doing so is quite unwise, especially when trying to mix -MTd and -MD, as the libraries and modes linked by these two are substantially different. You will have to find a way to link all libraries with the same settings, whatever that setting may be that works for all of your libraries. You might find that compiling your own Perl is more convenient to achieve your goal.

    All of these flags are compile time settings and change how the Perl executable itself (perl.exe and perl58.dll) is created, so changing any of these is best done when compiling your own Perl.

Re: Perl MakeMaker - how to force Perl linking with the static C library (libcrt.lib) instead of dynamic C library (msvcrt.lib)
by TGI (Parson) on Apr 17, 2007 at 23:13 UTC

    Can you write a thin wrapper around the static libraries and compile that for dynamic linking?

    I've never tried this, this is just a wild idea. You've been warned. ;)


    TGI says moo

Re: Perl MakeMaker - how to force Perl linking with the static C library (libcrt.lib) instead of dynamic C library (msvcrt.lib)
by spacepille (Acolyte) on May 09, 2009 at 22:28 UTC
    i have placed this code at the end of Makefile.PL:
    package MY; sub cflags { my $inherited = shift->SUPER::cflags( @_ ); if( $^O eq 'MSWin32' ) { $inherited =~ s/-O1/-O2/sg; # set static linking to crt $inherited =~ s/-MD/-MT/sg; } $inherited; } sub const_loadlibs { my $inherited = shift->SUPER::const_loadlibs( @_ ); if( $^O eq 'MSWin32' ) { # set static linking to crt $inherited =~ s/msvcrt\.lib/libcmt\.lib/sgi; } $inherited; }