How can I compile my Perl script so it can be executed on systems without 'perl' installed?

Perl

Perl Problem Overview


I have a .pl file and I want to execute that file in any system even though perl is not installed. How can I achieve it?

What would be some good examples to do that?

Perl Solutions


Solution 1 - Perl

pp can create an executable that includes perl and your script (and any module dependencies), but it will be specific to your architecture, so you couldn't run it on both Windows and linux for instance.

From its doc:

> To make a stand-alone executable, suitable for running on a machine that doesn't have perl installed: > > % pp -o packed.exe source.pl # makes packed.exe > # Now, deploy 'packed.exe' to target machine... > $ packed.exe # run it

(% and $ there are command prompts on different machines).

Solution 2 - Perl

  1. Install PAR::Packer. Example for *nix:

    sudo cpan -i PAR::Packer

    For Strawberry Perl for Windows or for ActivePerl and MSVC installed:

    cpan -i PAR::Packer

  2. Pack it with http://search.cpan.org/perldoc?pp">`pp`</a>;. It will create an executable named "example" or "example.exe" on Windows.

    pp -o example example.pl

This would work only on the OS where it was built.

P.S. It is really hard to find a Unix clone without Perl. Did you mean Windows?

Solution 3 - Perl

From perlfaq3's answer to How can I compile my Perl program into byte code or C?:


(contributed by brian d foy)

In general, you can't do this. There are some things that may work for your situation though. People usually ask this question because they want to distribute their works without giving away the source code, and most solutions trade disk space for convenience. You probably won't see much of a speed increase either, since most solutions simply bundle a Perl interpreter in the final product (but see How can I make my Perl program run faster?).

The Perl Archive Toolkit ( http://par.perl.org/ ) is Perl's analog to Java's JAR. It's freely available and on CPAN ( http://search.cpan.org/dist/PAR/ ).

There are also some commercial products that may work for you, although you have to buy a license for them.

The Perl Dev Kit ( http://www.activestate.com/Products/Perl_Dev_Kit/ ) from ActiveState can "Turn your Perl programs into ready-to-run executables for HP-UX, Linux, Solaris and Windows."

Perl2Exe ( http://www.indigostar.com/perl2exe.htm ) is a command line program for converting perl scripts to executable files. It targets both Windows and unix platforms.

Solution 4 - Perl

Look at PAR (Perl Archiving Toolkit).

> PAR is a Cross-Platform Packaging and > Deployment tool, dubbed as a cross > between Java's JAR and > Perl2EXE/PerlApp.

Solution 5 - Perl

And let's not forget ActiveState's PDK. It will allow you to compile UI, command line, Windows services and installers.

I highly recommend it, it has served me very well over the years, but it is around 300$ for a licence.

Solution 6 - Perl

Cava Packager is great on the Windows ecosystem.

Solution 7 - Perl

Perl files are scripts, not executable programs. Therefore, for them to 'run', they are going to need an interpreter.

So, you have two choices:

  1. Have the interpreter on the machine that you wish to run the script, or
  2. Have the script running on a networked (or Internet) machine that you remotely connect to (ie with a browser)

Solution 8 - Perl

On Mac OS X there may be perlcc. Type man perlcc. On my system (10.6.8) it's in /usr/bin. Your mileage may vary.

See perl-5.8.9 / perlcc.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUser1611View Question on Stackoverflow
Solution 1 - PerlysthView Answer on Stackoverflow
Solution 2 - PerlAlexandr CiorniiView Answer on Stackoverflow
Solution 3 - Perlbrian d foyView Answer on Stackoverflow
Solution 4 - PerlJared OberhausView Answer on Stackoverflow
Solution 5 - PerlMathieu LongtinView Answer on Stackoverflow
Solution 6 - PerlRickView Answer on Stackoverflow
Solution 7 - PerlDavid LewisView Answer on Stackoverflow
Solution 8 - PerlKlaas Z4us VView Answer on Stackoverflow