Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Free MSVC tools + Activestate to compile CPAN Modules

by jZed (Prior)
on Aug 31, 2004 at 00:03 UTC ( [id://387070]=perlmeditation: print w/replies, xml ) Need Help??

update In the YMMV vein, please see shay's Re: Building Perl with the free MSVC tools. The method below will apparently only work for some modules. I tried with DBI, DBD::SQLite, and Text::CSV_XS and they all work fine, so this method is useful for me regardless of what other modules it will or won't work with.

I got a new winXP box and wanted to be able to use perl (well, duh!) and to compile my own versions of CPAN modules without using cygqin bash or purchasing a compiler from Microsoft (not so duh, but not so hard either).

After attempting unsuccessfully to follow Building Perl with the free MSVC tools and through no fault of the excellent advice of corion++, intrepid++, demerphq++, I gave up and tried to just use the free tools to compile modules with activestate perl ... success!

Here's how:

Caution: these are humongous downloards (hundreds of mb). corion has a script which hopefully he'll share to wget just the needed portions. But here's how I did it with the full (*free* as in beer) downloads:

  1. Download and install Microsoft Visual C++ Toolkit 2003
  2. Download and install Microsoft SDK Platform Update
  3. Download and install .NET redistributable
  4. Download and install .NET SDK
  5. Set environment to recognize the bin/lib/inc dirs for all of those (update these assume the default install paths, but see demerphq's points below for reasons you might want to use short path names instead and for alternate ways to set the environment):
    @echo off
    set MSVC=C:\Program Files\Microsoft Visual C++ Toolkit 2003
    set MSSDK=C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7
    set Mstools=C:\Program Files\Microsoft SDK
    
    set INCLUDE=%MSVC%\include;%MSSDK%\include;%Mstools%\include
    set LIB=%MSVC%\lib;%MSSDK%\lib;%Mstools%\Lib;
    set PATH=%MSVC%\bin;%MSSDK%\bin;%Mstools%\Bin;%Mstools%\Bin\WinNT;%PATH%
    
  6. Download and install the latest (*free as in speech*) perl binary

  7. Download and install (*free as in speech*) cygwin (or just grab the needed tools - gzip, tar, cat, etc.)

  8. You can now use PPM or CPAN.pm or CPANPLUS or nmake to compile and install (many) CPAN modules ... Enjoy!
update : made URLs into links per bart's suggestion

Replies are listed 'Best First'.
Re: Free MSVC tools + Activestate to compile CPAN Modules
by demerphq (Chancellor) on Aug 31, 2004 at 07:31 UTC

    Cool great. BTW, a minor point or two, its better to set your paths by using the vcvars32.bat batch file, or to spawn a shell that is installed in the start menu that launches with it automatically. Also:

    If you want to avoid pain, don't put spaces in the install paths of anything above. Manually specify every path into a usefully short high level name. Don't use the defaults!

    Yes its possible to get everything working with spaces in the paths, but its much easier to avoid them in the first place. If you have problems with paths with spaces in them have a gander at junction to make a new directory that is an alias to the one with spaces in it. And then update your paths.

    Returning to paths its well worth the time IMO to transer all of the paths normally loaded by vsvars32.bat or vcvars32.bat into your system enviornment. The easiest way to do this is to in an open shell

    C:\>set > setenv.txt c:\>vsvars32 c:\>set > vsenv.txt c:\>diff setenv.txt vsenv.txt > diff.txt

    and then use the diff.txt to C&P the missing values into your system enviornment. This way if any of perls or cpans build enviornment spawns any of the c tools regardless of how or when you will always have the correct enviornment available.

    Additionally you can find a free version of nmake.exe here unpack it and put it in your path somewhere (or put where it is in your path, *shrug*).


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


      its better to set your paths by using the vcvars32.bat

      The set commands I listed above include the vcvars32.bat commands. But the vcvars32.bat does not set the environment for the SDK, only the Toolkit so it is not sufficienct by itself. You can save the set commands listed above as a batch file and run that *instead* of vcvars32.bat, or, as you point out, you can put these permanently in your enviornment (do as demerphq advices to make a diff, then, right click on my computer, select properties-advanced, select environment variables, find the PATH, LIB, and INCLUDE vars and set them with the output of the diff, or as I show above).

      If you want to avoid pain, don't put spaces in the install paths

      While I am sure you are right for most paths that have to do with perl, I do not believe that the spaces make any difference when they are meant (as the ones in the set commands above are) exclusively for use by windows. OTOH, the spaces bit me (and you helped me, thanks) when I tried to put the perl build (the one I unsuccessfully tried to build manually) in a directory with spaces. Your advice is probably safest as a general policy, but I really don't think it should or does make any difference for the compiler tools.

        but I really don't think it should or does make any difference for the compiler tools.

        My worry is that it may cause problems for such things as Inline.pm or ExtUtils::MakeMaker or various other cpan packages that involve compiling (some packages will try to compile little C snippets to see if your C compiler is available). Not all of these packages are smart enough to handle the various cross platform issues that come up, especially not spaces in the install paths.

        I _strongly_ recommend that you install as much as possible in paths with no spaces for this reason. For instance I usually install Visual Studio dotNet in E:\dotNet and not in the MS recommended ditrectories. Ive never had a problem as long as I did this. However every time i forget about this (when I build a new machine for instance) and I always end up getting bitten and having to junction or reinstall. So while im sure a lot of stuff will work fine, i think the safest plan, and the lowest stress is to avoid them. After all its always when you have 6 minutes to get something done that a CPAN install blows up and starts wining about not being able to find the compiler that is most definately there. :-)

        OTOH, im not going to get too strung out about it, after all Ive already installed them in directories without spaces in their names so it wont be me getting bitten. :-p


        ---
        demerphq

          First they ignore you, then they laugh at you, then they fight you, then you win.
          -- Gandhi


Re: Free MSVC tools + Activestate to compile CPAN Modules
by Corion (Patriarch) on Aug 31, 2004 at 06:54 UTC

    As a small, Perl-only starter set for the Unix Utilities, I now avoid downloading and installing cygwin and use the Win32 Unix Utils as found on http://unxutils.sourceforge.net, as the three programs needed by Perl are only tar, gzip and wget for good measure. With these, the ugly errors of mismatched cygwin1.dlls are gone, and these three programs are easily put where the perl.exe binary resides too.

      Yes, good point about the cygwin dlls. Also, make sure that your windows Perl is in your path *before* cygwin, otherwise you might end up using cygwin's perl by default.
Re: Free MSVC tools + Activestate to compile CPAN Modules
by strat (Canon) on Aug 31, 2004 at 06:49 UTC

    If you compile modules, you might need the same version of the compiler perl was compiled (if you use the Activestate-binary, I think you need VisualC6 (which works fine for me). But I don't know if you can download it for free, or at least the build tools)

    Well, with the free nmake you can compile a lot of cpan-modules, but for many you need the whole compiler suite (e.g. cl.exe and so on)

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

      If you compile modules, you might need the same version of the compiler perl was compiled (if you use the Activestate-binary, I think you need VisualC6

      That kind of thinking is what prevented me from trying this in the first place. Do you have any proof that purchasing and using VC6 is any different from using the free VC Toolkit I mention above when compiling using the ActiveState build? (not a rhetorical question, I'd like to know). So far I have not found any modules that don't work with the free version.

      Well, with the free nmake you can compile a lot of cpan-modules

      Strictly speaking, that isn't true. You can *install* non-XS modules with just nmake.exe but you need a compiler to *compile* XS modules. Nmake.exe comes included in the free SDK mentioned above so there is no need to download it separately. But you're right that nmake.exe by itself is useful for installing non-XS modules for those who don't want to or can't download the the full compiler.

        Generally you do need to use the same compiler to build CPAN modules as was used to build Perl.

        Upto version 6 of MSVC++ you can probably get away with using different versions: linking against msvcrt.lib always produced binaries depending on msvcrt.dll, which ships with the OS.

        However, from version 7 onwards (and the free toolkit is version 7) linking against msvcrt.lib now produces binaries depending on msvcr71.dll (or whatever the latest version is).

        ActivePerl is built using MSVC6, so if you build a module using the free tollkit then perl.exe will load msvcrt.dll and the module's DLL will load msvcr71.dll. If any CRT resources (e.g. file descriptors) are passed between the two then you'll have problems.

        I recently discovered this with one of my CPAN modules (Win32-UTCFileTime-1.32). I was able to fix it (in 1.33) by falling back to an OS-level filehandle if the passing of the CRT file descriptor failed. However, another of my modules (Win32-SharedFileOpen) definitely does not work with ActivePerl if built using the free toolkit -- it does much more passing around of CRT resources and can't be fixed as easily. The solution is either to build it with MSVC6, or rebuild Perl using the same compiler as is being used to build the module.

        Microsoft have a brief note about the perils of loading two different CRT DLL's at this URL (at the time of writing!): http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_c_run.2d.time_libraries.asp

        - Steve

      This is wrong. For a project I'm working on we compile an XS module using Cygwin's mingw32 compiler, we don't use the MakeMaker Makefile but a hand rolled one, but the generated .dll still loads fine with ActivePerl.

      Admitedly Cygwin is not much help with CPAN modules, as MakeMaker will produce nmake formated Makefiles, but if a mingw32 .dll will link fine then any version of MSVC should work.

Re: Free MSVC tools + Activestate to compile CPAN Modules
by Wassercrats (Initiate) on Aug 31, 2004 at 01:49 UTC
    I informed you in CB yesterday that I'd done research into this and pointed you to my scratchpad (top part for now--will eventually be removed), where I still have a little information that might be helpful. I don't know if you had me on ignore, or if it didn't apply to you, but you didn't respond to me.

    Incase anyone hasn't noticed, I occasionally try to help people here, and nobody has a good reason to /ignore me in CB. If you think you do, then post the reason, with adequate detail, to your home node to warn others about me.

      Wassercrats, thanks for trying to help, I must have missed your suggestion. I do not now and have never had you or anyone else on /ignore. I do try to ignore you (through mental powers, not with /ignore) when you are trying to dominate the CB with discussions about yourself or about ideas which appear to me to be introduced solely to provoke someone. OTOH, I applaud you for trying to be helpful. Thanks, I appreciate it, keep up the good work!

      update: just to be clear, I mean those last two sentences, I am not being sarcastic.

        I'll have to use my mental powers to upvote you, since I don't have the ability to do it any other way.
Re: Free MSVC tools + Activestate to compile CPAN Modules
by Courage (Parson) on Sep 01, 2004 at 05:27 UTC
    Your advices are low quality.
    • What should eb done for step 5? Its frustrating. For sure, there will be many breaks on that step.
    • Are you sure you have minimal set of downloads to do the task? For sure, the task could be performed with much less amount of garbage.
    • In case you beleive you add something usefull, why not proposing appropriate documentation patch to perl5developers? (AFAIK there were some postings in p5p recently about your topic)
    There are resaons why I do not insert tips for, say, compiling Perl for WinCE devices, despite of fact those could be useful because of growing amount of WinCE users roaming around. Those belong to their place.

    My point of view -- your posting must go to p5p and not here.

Re: Free MSVC tools + Activestate to compile CPAN Modules
by xdg (Monsignor) on Nov 17, 2007 at 19:17 UTC

    If anyone is trying this with a recent version of the free MSVC tools, please see Problems with FREE MS VC++ tools -- particularly the update about needing a perl.exe.manifest file for MSVC 8.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Free MSVC tools + Activestate to compile CPAN Modules
by mpeppler (Vicar) on Sep 30, 2004 at 10:43 UTC
    I just used this information to build PPDs for DBD::Sybase. These are now available with the other DBI binaries on http://ftp.esoftmatic.com/DBI/.

    Michael

      Like shay said, those binaries will depend on MSVCR71.dll, so it's only prudent to at least warn users (one way to warn).

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        Rats!

        OK - I'll see what needs to be done about that.

        Thanks.

        Michael

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://387070]
Approved by kvale
Front-paged by demerphq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-03-19 08:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found