Thursday, February 28, 2008

Compile Perl Into Win32 Executable Applications

Want to run Perl scripts on Windows systems that don't have Perl installed? Compile them into standalone executable applications!

There's always a way...

After much Googling and much frustration trying to get it to work, it did!

I am using ActiveState ActivePerl 5.8.8 Build 822 on my Windows XP systems. I read much about PAR & perlcc, etc. but nothing seemed to magically turn my paltry Perl scripts into mighty Windows Executable files. Finally I found the answer hidden away in a little URL tucked away on some message board.

Here's the short sweet version: You can add Perl module repositories with ActiveState's included Perl Package Manager. You add the repository and install PAR-Packer (not just any PAR-Packer, see below for the particulars).

  1. Open the Package Manager
  2. Click Edit Preferences (or the little gear icon on the left)
  3. Select the Repositories tab
  4. Enter a name in the Name field (I chose theoryx5 for obvious reasons following)
  5. Enter the following URL in the Location field:

    • http://theoryx5.uwinnipeg.ca/ppms/

  6. Click Add
  7. Click OK
  8. Click File --> Refresh All Data if the app doesn't do it automagically
  9. Click View --> All Packages
  10. In the Search field (you know, the field with the little magnifying glass in it) Enter Packer
  11. You will see a few listings (or maybe more then a few, depending). Two in particular you will find: PAR-Packer 0.976 & PAR-Packer-588 0.973. Select the first (the one without the -588 this is important!).
  12. Either right-click on it and choose Install... or click the little package icon that has the green + on it.
  13. Click the little play arrow icon or choose Action Install... at the top
  14. Once it's installed with all it's dependencies, close the Package Manager
  15. Add the following to your path (if Perl is found at C:\Perl): C:\Perl\site\bin;

    1. In Windows XP you can do this by right-clicking My Computer
    2. Click Properties
    3. Select the Advanced tab
    4. Click Environment Variables
    5. Scroll down in System variables & select Path
    6. Click Edit
    7. Add C:\Perl\site\bin; to your path
    8. Click OK & exit Evironmental variables, etc.
    9. You may need to log off and back on for the change to take effect

Now open up a Windows shell (you know, Start --> Run --> cmd --> OK), navigate to the directory with your perl script to compile and enter: pp -o myfile.exe myfile.pl and ta-da your newly minted .exe will magically appear.

Well, it should anyway. Remember, use this at your own risk, your millage may vary, etc. etc.

It worked for me and I was very happy.

Note: You can review all of the available packages for the aforementioned repository at the same URL: http://theoryx5.uwinnipeg.ca/ppms/