Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Note-- Not everyone thinks that packing up perl applications into executables is a good idea. I am aware of the drawbacks (and do mention them, see "caveats"), but think there are some cases where it is useful. After fiddling around with App::Packer, I thought I'd share a step-by-step tutorial for those who need it.


Have you had .EXE-envy? That is, have you ever wished it would be as easy to ship your perl applications as it is with C/C++ or VisualBasic programs, without having to make sure perl is installed on the user's computer? If yes, you probably heard of perl2exe. And probably were discouraged by the steep price tag. Mattia Barbon created a wonderful set of modules distributed as App::Packer that can do the same thing for you. For free, and with source included.

This tutorial is geared towards not-so-experienced users of perl on Win32 platforms. Much of it should apply for Linux/Unix as well.


App::Packer is not a compiler. It merely packs up your script as well as all the modules needed in a nice bundle. This means:

  • Your application will remain an interpreted perl script.
  • Your source code will still be accessible.
  • The run-time behaviour will be the same.
  • The startup time will actually be longer, because the "bundle" needs to be unpacked when the application is started.
  • You will need to ship additional DLL files.

For some applications, it might be much more practical to create a perl "distribution" on CD containing ActivePerl or IndigoPerl and the additional modules you are using, together with your application.

Installing App::Packer

First, do a binary install using ppm:

ppm install

Additionally, you need a modified version of Module::Info, available from Install it using the usual procedure:

perl Makefile.PL
nmake install

If you don't have nmake yet, get it by downloading nmake15.exe.

Creating an executable

There is a script supplied with App::Packer, which should be inside the directory perl\site\lib\App. You might want to copy it to another directory for your convenience. The first step to create an executable is

perl -o myapp.exe

If your script is using a lot of modules, this might take a while, because

App::Packer needs to find out the dependencies between the modules used, so if your script is using a lot of modules, this might take a while. This is especially true for large GUI packages like Wx. Future calls of will be much faster because the information about the modules analyzed is stored in a cache.

Something's missing... (1)

When starting the newly generated program, you might encounter a Windows error message about missing library files. This is probably because you are using a XS module. On Win32, perl stores the binary code in XS modules as DLL files inside your module paths. Unfortunately, Windows doesn't tell you the exact name of the DLL. If you have no idea which file is missing, get Dependency Walker. Run it, drag'n'drop your executable on it and select Profile|Start Profiling from the menu. After a while, your program will abort and Dependency Walker displays the name of the DLL that is missing. Go to your perl directory, search it for that DLL (usually it is somewhere in perl\site\lib\auto) and copy it over into your executable's directory. If your PATH variable doesn't include your perl directory, you will also need to copy the perl DLL (usually called something like perl\bin\perl56.dll).

Something's missing... (2)

Having done that, you might still encounter perl error messages that tell you that a certain module could not be found. Sometimes modules use other modules in weird ways that App::Packer doesn't understand. For example, XML::Parser uses File::Spec. In this case, call as follows:

perl -o myapp.exe --add-module File::Spec

You can use --add-module several times to add several modules.

Shipping your application

When sharing your application with others, make sure you include all the DLL files needed. Even if you do not use any other module and your executable runs "out of the box" on your computer, you will still need to include the perl DLL as mentined above, or else others will not be able to execute your application.

The finishing touches

The created executable is a console application, so you will still see a console window after you started it. To prevent this, you need to change the executable type. Download the source code for, then do a

perl myapp.exe WINDOWS


Final thoughts

More information about App::Packer can be found on CPAN. If you like it, consider sending Mattia Barbon an e-mail to praise him for his work. If you have any amendments or corrections for this tutorial, please drop me a line. Thanks to Valdez for telling me about App::Packer.

Large apps can take quite a while to start up, e.g. when using Wx, XML::Parser etc. Small apps tend to start very quickly. A "Hello world" can amount to ~15 KB (+ perl DLL) and run faster than you can blink, so don't hesitate to use this approach for small utilities, designed to be run e.g. on Windows startup.

EDIT: added readmore tag, edited final thoughts

In reply to Shipping standalone perl apps on Win32 by crenz

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2023-01-31 09:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found