Posted by perlman on Sep 21, 2011 in Programming | 3 comments
Can anyone tell me how to compile a Perl file so I can turn it into an EXE for someone and allow them to run it without having Perl installed?
How can I make a .pl file a .exe?
Compiling Perl files (making perl files into exes, convert perl to exe, or just perl to exe) can be EXTREMELY problematic. There are a number of tools (not THAT many but there's a handful) and many aren't supported any more.
The best way I have found to make a perl file into an exe (or compile a perl file) is using the module PAR::Packer from http://search.cpan.org/search?mode=module&query=PAR%3A%3APacker.
To get started you need to connect to the right ppm depository to download Par::Packer and you'll need to know what version of Perl you are using as well as what build number.
After knowing which version of Perl you are using, open a command prompt and copy/paste the ppm commands below for the version you require. (note: Although you should use just the one for your version, I tested the install after applying each of the commands below and the module worked just fine. So if you're not sure which version you need, install each of them and it should be just fine.)
Perl 5.12 and PPM4 (builds 1200+): ppm rep add trouchelle.com http://trouchelle.com/ppm12/
Perl 5.10 and PPM4 (builds 1000+): ppm rep add trouchelle.com http://trouchelle.com/ppm10/
Perl 5.8 and PPM4 (builds 820+) AND Perl 5.8 and PPM3 (builds 817): ppm rep add trouchelle.com http://trouchelle.com/ppm/
Install PAR::Packer. In the command prompt that is already open, enter the command: ppm install Par::Packer to launch the installer.
Unfortunately the module package is broken and we need to edit a file to get it to work properly. Navigate to C:\Perl\lib and locate the Config.pm file. Right-click Config.pm and remove the READ ONLY permission on it. Then open the file in notepad.
In Config.pm, search for $^V eq 5.12.2 which isn't too far from the top. Replace that with $^V eq 5.12.2 or $^V eq 5.12.0 . (note: if at run time you get an error after this saying you don't have the correct version, it will tell you what version you have. Simply reopen th file and change the second version number you just added to the number you are using). Save the file.
Convert your Perl script to an exe using the commands shown on http://search.cpan.org/search?mode=module&query=PAR%3A%3APacker .
Sample command: pp -o newfilename targetfile.pl
Where the newfilename is the file the Perl EXE file will be named and the targetfile.pl is where the Perl file you want to convert is.
That's it! It may seem like a tedious process to convert Perl to an EXE file but once you have the right module installed and know how to throw the pp command at the command line it really is simple.
One final note: There are users who are still asking about perlcc and trying to get that module to compile their Perl files into exe files. Unfortunately this module was never removed from experimental stage and never worked that well. It was supposed to be removed from the Perl CORE back in 2006 if I recall correctly but for whatever reason it is still found in the latest Perl distro (as of Sept 21, 2011). If you are trying to use perlcc to compile the Perl file to an exe, DON'T BOTHER. It simply will not work.
i have to give this a try. i've always wondered if this was possible to convert perl to an exe file. thanks!
Was this answer helpful?
The output is a little large (I think it was 3.56MB for a test perl script of under 50 lines of code) but it worked perfectly the first time following your instructions above. BTW i just installed all the ppm servers to save time and that worked for me. Many thanks
Mail (will not be published) (required)