Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PerlApp - Shared Libraries?

Status
Not open for further replies.

Kirsle

Programmer
Joined
Jan 21, 2006
Messages
1,179
Location
US
I was wondering if anyone has figured out how to share libraries between compiled PerlApp programs.

For example, if I have three different Perl scripts that all use Perl/Tk, and compile each one independently, then each program is automatically 3 MB in size because each one has the entire Tk library in it.

Is there a way to maybe have PerlApp write the Tk library into a DLL file, and just have the three programs use that DLL, so that the DLL is the 3 MB but each program would only be a matter of kilobytes?

Thanks in advance.
 
You might want to look at PAR

Let us know your results!

X
 
I tried using PAR... here are my results:

I zipped my C:\usr\site\lib\Tk folder (and Tk.pm and Tk.pod) into a zip file, Tk.zip, which I renamed to Tk.par and put in my test folder.

I had three scripts, blue.pl, red.pl, and purple.pl... here's the code for one of them:

Code:
#!/usr/bin/perl -w

use PAR "Tk.par";
use Tk;

my $main = MainWindow->new (
	-title => 'Red Window',
);
$main->Label (
	-font => [
		-size => 32,
	],
	-foreground => 'red',
	-text => 'Hello World!',
)->pack;

MainLoop;

When run as a Perl script, these scripts would run just fine. I compiled blue.pl in PerlApp, trimming the Tk:: modules from compilation (because they are in Tk.par and should be loaded by PAR when the program runs).

PerlApp gave this error when testing the newly compiled blue.exe:

Code:
Can't locate Tk.pm in @INC (@INC contains: CODE(0xbfe934)) at blue.pl line 5.
BEGIN failed--compilation aborted at blue.pl line 5.

I tried putting the "use Tk;" into an eval statement, so that the Perl interpreter which is compiled along with the programs wouldn't try to load Tk before it tries to load PAR.

Code:
#!/usr/bin/perl -w

use PAR "Tk.par";
eval {
	use Tk;
};

my $main = MainWindow->new (
	-title => 'Blue Window',
);
$main->Label (
	-font => [
		-size => 32,
	],
	-foreground => 'blue',
	-text => 'Hello World!',
)->pack;

MainLoop;

I've tried these too:

Code:
eval "use Tk;";
require Tk;

Both of these, when running the Perl script normally, gave a warning

Code:
Useless use of a constant in void context at F:\Perl\tests\PAR\blue.pl line 17.

And line 17 was the "MainLoop;" line. The Tk window didn't open, and the program quit after about a second. Since it can't be run normally with these other two codes, they wouldn't be able to run when compiled either. So the only way I could eval a loading of Tk was to put it in an eval {block}.

Any other ideas?
 
I found one solution thus far...

I made a simple Perl script which I named libtk.pl:

Code:
#!/usr/bin/perl -w

use Tk;

I opened this up in PerlApp and compiled it with the option "Share with Anybody" to make a shared executable. I compiled it into a file named "libtk.dll"

It may not be a valid DLL file, since it was supposed to compile into an EXE, but seems to how this Perl script didn't do anything except for load Tk, it wouldn't make sense to name it as an EXE because people would run it and it wouldn't do anything for them.

So, libtk.dll

Then I took one of my test scripts, blue.pl:

Code:
#!/usr/bin/perl -w

use Tk;

my $main = MainWindow->new (
	-title => 'Blue Window',
);
$main->Label (
	-font => [
		-size => 32,
	],
	-foreground => 'blue',
	-text => 'Hello World!',
)->pack;

MainLoop;

In PerlApp, I added in the "Module Search Path", a shared executable and gave it the path to libtk.dll, and specified a run directory of "."

So, I compiled that into blue.exe, and the executable size is only 472 KB. As long as it can find libtk.dll in ".", it runs fine. Otherwise it echoes an error to command prompt something along the lines of:

Code:
F:\Perl\tests\New Folder>purple.exe
Error: cannot load shared library 'F:\Perl\tests\New Folder\libtk.dll'

My first concern was that it was loading libtk.dll from an absolute path, so I cut-and-pasted all the files into other folders, tried renaming libtk.dll to "ruin" its chance of being found, and the error message reflected the new file path.

So, in essence, I've created a DLL file for Perl/Tk which can be used by any PerlApp EXE which is set to use it as a shared executable, so they can load the Tk modules out of it.

So... this solution bypassed everything that PAR stands for, but I tinkered around with PAR a lot and didn't find a way to do it with that.

But on that note, this code, seen in PAR::Tutorial, didn't work for me:

Code:
use PAR;
use lib "Tk.par";

Code:
Parameter to use lib must be directory, not file at F:\Perl\tests\New Folder\blue.pl line 4
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top