39

What would be the easiest way to compile a simple Perl script to an executable under Windows with Strawberry Perl (as I understand it's possible and free)?

In the past I've used ActiveState compiler and perl2exe and was simple enough. However, now after a few computer changes and OS updates I've lost the licenses and I'd like to find a better/permanent solution.

Smi
  • 13,850
  • 9
  • 56
  • 64
Notitze
  • 1,249
  • 2
  • 13
  • 22
  • Dupes http://stackoverflow.com/questions/1237286 and http://stackoverflow.com/questions/446685 – daxim Jun 01 '10 at 09:09
  • possible duplicate of [How can I deploy a Perl/Python/Ruby script without installing an interpreter?](http://stackoverflow.com/questions/446685/how-can-i-deploy-a-perl-python-ruby-script-without-installing-an-interpreter) – P Shved Dec 28 '10 at 19:02
  • Possible duplicate of [How can I compile my Perl script so it can be executed on systems without perl installed?](https://stackoverflow.com/questions/1237286/how-can-i-compile-my-perl-script-so-it-can-be-executed-on-systems-without-perl-i) – m13r Mar 28 '18 at 14:42

4 Answers4

31

Install PAR::Packer from CPAN (it is free) and use pp utility.

szabgab
  • 6,202
  • 11
  • 50
  • 64
Alexandr Ciornii
  • 7,346
  • 1
  • 25
  • 29
  • 2
    Instructions here: http://n3ncy.com/PERL/ and here: http://stackoverflow.com/questions/1237286/how-can-i-compile-my-perl-script-so-it-can-be-executed-on-systems-without-perl-in/1241379#1241379 – Notitze Jun 01 '10 at 10:45
  • 4
    Note: PAR::Packer/pp comes with a manual: http://search.cpan.org/perldoc?pp For a fairly in-depth overview of what you can do with PAR, have a look at my talk from YAPC::EU 2008 http://steffen-mueller.net/talks/appdeployment/ – tsee Jun 01 '10 at 16:13
  • This doesn't seem to work for me http://stackoverflow.com/questions/9588100/installing-parpacker-on-windows-dmake-error-255 – bag-man Mar 06 '12 at 17:24
  • 1
    @Notitze - bad link – dgo Jul 18 '17 at 13:27
18
  :: short answer :
  :: perl -MCPAN -e "install PAR::Packer" 
  pp -o <<DesiredExeName>>.exe <<MyFancyPerlScript>> 

  :: long answer - create the following cmd , adjust vars to your taste ...
  :: next_line_is_templatized
  :: file:compile-morphus.1.2.3.dev.ysg.cmd v1.0.0
  :: disable the echo
  @echo off

  :: this is part of the name of the file - not used
  set _Action=run

  :: the name of the Product next_line_is_templatized
  set _ProductName=morphus

  :: the version of the current Product next_line_is_templatized
  set _ProductVersion=1.2.3

  :: could be dev , test , dev , prod next_line_is_templatized
  set _ProductType=dev

  :: who owns this Product / environment next_line_is_templatized
  set _ProductOwner=ysg

  :: identifies an instance of the tool ( new instance for this version could be created by simply changing the owner )   
  set _EnvironmentName=%_ProductName%.%_ProductVersion%.%_ProductType%.%_ProductOwner%

  :: go the run dir
  cd %~dp0

  :: do 4 times going up
  for /L %%i in (1,1,5) do pushd ..

  :: The BaseDir is 4 dirs up than the run dir
  set _ProductBaseDir=%CD%
  :: debug echo BEFORE _ProductBaseDir is %_ProductBaseDir%
  :: remove the trailing \

  IF %_ProductBaseDir:~-1%==\ SET _ProductBaseDir=%_ProductBaseDir:~0,-1%
  :: debug echo AFTER _ProductBaseDir is %_ProductBaseDir%
  :: debug pause


  :: The version directory of the Product 
  set _ProductVersionDir=%_ProductBaseDir%\%_ProductName%\%_EnvironmentName%

  :: the dir under which all the perl scripts are placed
  set _ProductVersionPerlDir=%_ProductVersionDir%\sfw\perl

  :: The Perl script performing all the tasks
  set _PerlScript=%_ProductVersionPerlDir%\%_Action%_%_ProductName%.pl

  :: where the log events are stored 
  set _RunLog=%_ProductVersionDir%\data\log\compile-%_ProductName%.cmd.log

  :: define a favorite editor 
  set _MyEditor=textpad

  ECHO Check the variables 
  set _
  :: debug PAUSE
  :: truncate the run log
  echo date is %date% time is %time% > %_RunLog%


  :: uncomment this to debug all the vars 
  :: debug set  >> %_RunLog%

  :: for each perl pm and or pl file to check syntax and with output to logs
  for /f %%i in ('dir %_ProductVersionPerlDir%\*.pl /s /b /a-d' ) do echo %%i >> %_RunLog%&perl -wc %%i | tee -a  %_RunLog% 2>&1


  :: for each perl pm and or pl file to check syntax and with output to logs
  for /f %%i in ('dir %_ProductVersionPerlDir%\*.pm /s /b /a-d' ) do echo %%i >> %_RunLog%&perl -wc %%i | tee -a  %_RunLog% 2>&1

  :: now open the run log
  cmd /c start /max %_MyEditor% %_RunLog%


  :: this is the call without debugging
  :: old 
  echo CFPoint1  OK The run cmd script %0 is executed >> %_RunLog%
  echo CFPoint2  OK  compile the exe file  STDOUT and STDERR  to a single _RunLog file >> %_RunLog%
  cd %_ProductVersionPerlDir%

  pp -o %_Action%_%_ProductName%.exe %_PerlScript% | tee -a %_RunLog% 2>&1 

  :: open the run log
  cmd /c start /max %_MyEditor% %_RunLog%

  :: uncomment this line to wait for 5 seconds
  :: ping localhost -n 5

  :: uncomment this line to see what is happening 
  :: PAUSE

  ::
  :::::::
  :: Purpose: 
  :: To compile every *.pl file into *.exe file under a folder 
  :::::::
  :: Requirements : 
  :: perl , pp , win gnu utils tee 
  :: perl -MCPAN -e "install PAR::Packer" 
  :: text editor supporting <<textEditor>> <<FileNameToOpen>> cmd call syntax
  :::::::
  :: VersionHistory
  :: 1.0.0 --- 2012-06-23 12:05:45 --- ysg --- Initial creation from run_morphus.cmd
  :::::::
  :: eof file:compile-morphus.1.2.3.dev.ysg.cmd v1.0.0
Yordan Georgiev
  • 5,114
  • 1
  • 56
  • 53
5

There are three packagers, and two compilers:

free packager: PAR
commercial packagers: perl2exe, perlapp
compilers: B::C, B::CC

http://search.cpan.org/dist/B-C/perlcompile.pod

(Note: perlfaq3 is still wrong)

For strawberry you need perl-5.16 and B-C from git master (1.43), as B-C-1.42 does not support 5.16.

rurban
  • 4,025
  • 24
  • 27
0

BoxedApp Packer I found this application on the internet and it works fine with small perl files (Pl & PM) but for huge lib files don't think so :(

BoxedApp Packer

https://www.boxedapp.com/boxedapppacker/usecases/pack_perl_script_into_single_exe.html

if anyone have a tutorial for PAR::Packer with steps on windows I already installed perl strawberry - active state and par packer but the only thing I found it to convert only one perl file

pp -o example.exe example.pl

I need to convert main_project_file.pl file and all lib related.pm modules files into one exe file using PAR::Packer on windows

Amr Omran
  • 3
  • 2