Jul 20

Compile a perl script that uses Wx with pp and PAR

Category: Linux,Perl   — Published by tengo on July 20, 2008 at 9:30 am

Compiling scripts with pp, PAR's helper script, to executable binaries (.exe files on Win32) should be a pretty straightforward process. Anyway, if you are developing GUI applications, probably with Wx, you will surely run into some problems.

Upon execution, the generated execs will complain about missing libraries, DLLs or similar. This is because pp does a lot, but it is somehow blind to see the Wx bindings dependencies. So you need to tell it that you have additional libraries for it to include in the build. You can do so by using the -M switch, or by using Mark Dootson's excellent Wx::Perl::Packager! On Win32 ActivePerl setups, you might want to do "ppm install http://www.wxperl.co.uk/repository/Wx-Perl-Packager.ppd", as not all repositories carry a ppm for this module.

Then, simply add this line at the very top of your Wx-using script:

use Wx::Perl::Packager;

and then use Wx::Perl::Packager's "wxpar" drop-in replacement for pp. So, to compile, do:

wxpar -o myapp.exe myapp.pl

optionally adding a bit of salt like in the docs

wxpar --gui --icon=myicon.ico -o myprog.exe myscript.pl

and there you go.

Update 27th February 2009:

I just found this draft, that centers around the standard pp+par process of compiling a simple (non Wx script) on Windows and on Linux. A bit incomplete but still... For your reference and additional insight, here it is:

On Windows

First, you need to get PAR, PAR::Dist and PAR::Packer. It's probably okay to just install all of them, but if you want to understand the difference between PAR and PAR::Packer read this.Depending on what build of ActivePerl you are running, it might be you need to add a repository which has these packages to your ppm. If you have the graphical ppm, add reps via Edit > Preferences > Repositories. Versions ppm3 and below use the "rep add XXX xxx"syntax. See this page for more information.

After that, pp should be available from the command line. If not, look into your C:\Perl directory and see if pp is under /bin or /site/bin. If it is under /site/bin, you need to add this path to your environment, so you can easily execute it from your script's directory.

set PATH=C:\Perl\site\bin;%PATH%

Then test your setup and pp with this one-liner

pp -o hello.exe-e"print 'Hello World!';"

If you get errors here, the most common problem is that your setup is a patchwork of versions, that do not line up. Try to get everything on a more or less common version level.

On Linux

The process on Linux is essentially the same. Of course, you can forget all this ActivePerl related stuff, and install mostly through plain cpan.

One Problem I encountered while installing PAR::Packer was that cpan complained it "cannot find -lperl". A problem that seems to appear more often on Ubuntu machines. As stated in this thread I could solve the error by installing the libperl-devel package:

sudo apt-get install perl-devel