Compiling perl source using pp - perl

I have a perfectly functioning perl script (written in bash terminal on debian linux) that fails to execute (on either linux or windows) when compiled using pp. This may relate to unmet dependencies in the build, but I do believe the following command packages all dependencies into the executable:
pp -o out.exe in.pl
When I say it is perfectly functioning, I mean that the intended output is generated with no errors if I invoke ./in.pl from a bash terminal.
I would like to create an executable that will run on either linux or windows (if a separate file is required for each OS, so be it).
These are the packages that are included in the source:
use strict;
use warnings;
use charnames ":short";
binmode(STDOUT,":utf8");
use Term::ANSIColor;
use Number::Format;
use Finance::Quote;
use Finance::QuoteHist;
use Date::Manip; # this may be included by Finance::QuoteHist
If it helps, here is the error message I get (warning, it's long):
ERROR: [config_var] invalid zone in SetDate
ERROR: [config_var] invalid zone in SetDate
Could not load either Text::CSV_XS or Text::CSV_PP : Can't locate Text/CSV_PP.pm in #INC (#INC contains: CODE(0x1422320) /tmp/par-username/cache-addd1cc2ee9285c150584c1853c2b67c0c482e7e/inc/lib /tmp/par-username/cache-addd1cc2ee9285c150584c1853c2b67c0c482e7e/inc CODE(0x11675b0) CODE(0x116ebc8)) at (eval 30) line 2.
BEGIN failed--compilation aborted at (eval 30) line 2.
at Finance/QuoteHist.pm line 13
Compilation failed in require at Finance/QuoteHist.pm line 13.
BEGIN failed--compilation aborted at Finance/QuoteHist.pm line 13.
Compilation failed in require at script/in.pl line 10.
BEGIN failed--compilation aborted at script/in.pl line 10.
Judging from the run-time errors, the problem may relate to unmet recursive dependencies (for instance, dependencies within Finance::QuoteHist). Perhaps these recursive dependencies should be included explicitly? This is my first time attempting to compile perl into an executable, so thanks for any guidance you can provide.

You might try to use the -x flag to pp as seen in the docs. It runs the script and checks for dependencies as it goes, which is more accurate than simply scanning for dependencies. I have needed this when using Tk and it worked wonders.

Related

Perl CPAN Can't locate CPAN/Author.pm... when trying to install nipe

I'm trying to install "nipe" on my Windows Machine but i get this error code all the time. I have installed Strawberry Perl.
This is the error code:
Can't locate CPAN/Author.pm in #INC (you may need to install the CPAN::Author module) (#INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl) at /usr/share/perl5/core_perl/CPAN.pm line 19.
BEGIN failed--compilation aborted at /usr/share/perl5/core_perl/CPAN.pm line 19.
Compilation failed in require at /usr/share/perl5/core_perl/App/Cpan.pm line 290.
BEGIN failed--compilation aborted at /usr/share/perl5/core_perl/App/Cpan.pm line 290.
Compilation failed in require at /c/Strawberry/perl/bin/cpan line 7.
BEGIN failed--compilation aborted at /c/Strawberry/perl/bin/cpan line 7.
While you may have Strawberry Perl installed, that's not the perl you are using. C:\Strawberry\perl\bin\cpan uses the first perl in your PATH, which isn't your installation of Strawberry Perl. It appears that you are using some unix emulation (Cygwin? MSYS?) and using the perl from that emulation.
To use your Strawberry Perl build of perl, you could adjust your PATH so that SP comes before whatever perl you ended up using, or you could use
C:\Strawberry\perl\bin\perl C:\Strawberry\perl\bin\cpan Try::Tiny Config::Simple JSON
or
C:\Strawberry\perl\bin\perl -MCPAN -e"install #ARGV" Try::Tiny Config::Simple JSON
in lieu of
cpan Try::Tiny Config::Simple JSON
Similarly, if you don't adjust your path, you'll need to use
C:\Strawberry\perl\bin\perl nipe.pl ...
in lieu of
perl nipe.pl ...
If your are using windows and a bash then try to it with cmd or powershell after you applied the changes from #ikegami. Took me some time to figure out, that it had no effect to change the paths for this terminal, as it still took the paths from /usr//perl5/
I tried to do all of the other answers, but it didn't work. Instead it appeared that it doesn't work because I tried to run it from unix shell script (sh in powershell or git bash). After moving it from .sh to .ps1 and running non-unix way it works perfectly.

Can't locate Text/Soundex.pm in #INC

I was installing repeatsmasker and it apparently seems to work because it shows "Congratulations! RepeatMasker is now ready to use."
But when I run it it reports "Can't locate Text/Soundex.pm...". so I installed the module by "sudo cpan Text::Soundex", and by the end it tells me "Text::Soundex is up to date (3.05)." It seems the module is already installed, but RepeatMasker still has the same problem, as I'll show you in this code:
fragua#picci:~/RM/RepeatMasker$ sudo cpan Text::Soundex
Loading internal null logger. Install Log::Log4perl for logging messages
Reading '/home/fragua/.cpan/Metadata'
Database was generated on Fri, 19 Apr 2019 22:17:03 GMT
Text::Soundex is up to date (3.05).
fragua#picci:~/RM/RepeatMasker$ ./RepeatMasker -s -lib /home/fragua/RepeatScout-1.0.5/ObiINK5k_repeats_filtered1.fasta /home/fragua/Documenti/Workdirectory/ObiINC5k.fa
Can't locate Text/Soundex.pm in #INC (you may need to install the Text::Soundex module) (#INC contains: /home/fragua/RM/RepeatMasker /home/fragua/perl5/lib/perl5 /home/fragua/anaconda/lib/site_perl/5.26.2/x86_64-linux-thread-multi /home/fragua/anaconda/lib/site_perl/5.26.2 /home/fragua/anaconda/lib/5.26.2/x86_64-linux-thread-multi /home/fragua/anaconda/lib/5.26.2 .) at /home/fragua/RM/RepeatMasker/Taxonomy.pm line 80.
BEGIN failed--compilation aborted at /home/fragua/RM/RepeatMasker/Taxonomy.pm line 80.
Compilation failed in require at ./RepeatMasker line 310.
BEGIN failed--compilation aborted at ./RepeatMasker line 310.
I installed RepeatMasker in another computer without problems, but I don't know why now I encontered this problem
You have two builds of Perl installed:
/usr/bin/perl
/home/fragua/anaconda/bin/perl.
/home/fragua/anaconda/bin/perl is first in your PATH. This means that programs with the following shebang (#!) line will use /home/fragua/anaconda/bin/perl:
#!/usr/bin/env perl
RepeatMasker appears to be such a program.
All of this is fine.
The Problem
/home/fragua/anaconda/bin contains the scripts installed by /home/fragua/anaconda/bin/perl. As part of the installation process of these scripts, the shebang line of these scripts should have been rewritten to specify /home/fragua/anaconda/bin/perl.
However, the shebang line of /home/fragua/anaconda/bin/cpan references /usr/bin/perl. This means that using /home/fragua/anaconda/bin/cpan would install modules for /usr/bin/perl, not /home/fragua/anaconda/bin/perl.
The Workaround
You could avoid relying on the shebang line and explicitly specify the correct perl.
/home/fragua/anaconda/bin/perl /home/fragua/anaconda/bin/cpan Text::Soundex
Or, given your $PATH,
perl /home/fragua/anaconda/bin/cpan Text::Soundex
The Fix
To fix this problem in an ongoing manner requires changing the shebang lines of the scripts to be what they should be. In every file in /home/fragua/anaconda/bin (and in particular for cpan), replace
#!/usr/bin/perl
with
#!/home/fragua/anaconda/bin/perl
You could do this use the following (which does a backup of the files it changes):
perl -0777ne'print "$ARGV\n" if m{^#!\s*/usr/bin/perl\b}' /home/fragua/anaconda/bin/* \
| xargs perl -i~ -0777pe's{^#!\s*/usr/bin/perl\b}{#!/home/fragua/anaconda/bin/perl}'

Unable to load (and reinstall) Socket.pm after upgrade

I've just upgraded Slackware64 to 14.1 and I found Perl 5.18 in it. Socket.pm now complains that it was compiled for another Perl version, which was 5.16. Here is the error:
Perl API version v5.16.0 of Socket does not match v5.18.0 at /usr/share/perl5/XSLoader.pm line 92.
Unfortunately, I'm even unable to reinstall Socket.pm even with cpan.
$ cpan Socket
Reading '/home/francesco-salix/.cpan/Metadata'
Database was generated on Tue, 26 Nov 2013 09:08:12 GMT
Running install for module 'Socket'
Running make for P/PE/PEVANS/Socket-2.013.tar.gz
Checksum for /home/francesco-salix/.cpan/sources/authors/id/P/PE/PEVANS/Socket-2.013.tar.gz ok
CPAN.pm: Building P/PE/PEVANS/Socket-2.013.tar.gz
Attempt to reload Socket.pm aborted.
Compilation failed in require at /usr/share/perl5/IPC/Cmd.pm line 46.
BEGIN failed--compilation aborted at /usr/share/perl5/IPC/Cmd.pm line 46.
Compilation failed in require at /usr/share/perl5/ExtUtils/CBuilder/Base.pm line 11.
BEGIN failed--compilation aborted at /usr/share/perl5/ExtUtils/CBuilder/Base.pm line 11.
Compilation failed in require at /usr/share/perl5/ExtUtils/CBuilder/Platform/Unix.pm line 4.
BEGIN failed--compilation aborted at /usr/share/perl5/ExtUtils/CBuilder/Platform/Unix.pm line 4.
Compilation failed in require at (eval 6) line 2.
BEGIN failed--compilation aborted at (eval 6) line 2.
Compilation failed in require at Makefile.PL line 19.
Warning: No success on command[/usr/bin/perl5.18.1 Makefile.PL]
'YAML' not installed, will not store persistent state
PEVANS/Socket-2.013.tar.gz
/usr/bin/perl5.18.1 Makefile.PL -- NOT OK
Running make test
Make had some problems, won't test
Running make install
Make had some problems, won't install
Could not read metadata file. Falling back to other methods to determine prerequisites
As far as I've understood, Socket.pm is a Perl core module. So, I thought it would have been upgraded together with Perl.
Here are directories currently in #INC:
$ perl -E'say for #INC'
/home/francesco-salix/perl5/lib/perl5/x86_64-linux-thread-multi
/home/francesco-salix/perl5/lib/perl5
/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5
.
I see some folders seems duplicate, but I don't actually know if they are supposed to be like that. However, there's no Socket.pm in the first two path (which I assume where added by cpan while running under my user, while I've a Socket.pm file for both /usr/local/lib64/perl5/ and /usr/lib64/perl5.
Socket.pm is indeed a core module. And the CPAN.pm moduleExtUtils::MakeMaker uses it (via IPC::Cmd), so if Socket.pm is broken, CPAN.pmMakefile.PL will be broken too.
Given that it is a core module, and would have been installed with Perl, this suggests to me that Perl is trying to load Socket.pm from some other, older path. The following will tell you where Perl is trying to load modules from:
perl -E'say for #INC'
Is there anything suspicious in there. Any place it might find older modules compiled for Perl 5.16?
The solution is to clear the old modules, following 3rensho’s comment:
sudo rm -rf /usr/local/lib64/perl5/*
sudo rm -rf /usr/local/share/perl5/*
It works!

twiki "Failed to load the perl module FindBin."

I am trying to get TWIKI to work (virtual Server Hosteurope .. PLESK 11 CentOS 6).
When I run the configure script the following error appears:
[root#lvpsx.x.x.x bin]# ./configure
Failed to load the perl module FindBin. The module was found at /usr/share/perl5/FindBin.pm
Please ensure that:
1 FindBin is installed,
2 that the module is available on the #INC path,
3 that the webserver user (root) has permission to read the FindBin.pm file.
The detailed error seen was:
Subroutine export_fail redefined at /usr/share/perl5/Carp.pm line 25.
Compilation failed in require at /usr/share/perl5/FindBin.pm line 95.
BEGIN failed--compilation aborted at /usr/share/perl5/FindBin.pm line 95.
Compilation failed in require at (eval 3) line 2.
BEGIN failed--compilation aborted at (eval 3) line 2.
I have only marginal knowledge about the usage of shells and much less experience with Perl.
I run the configure script as root. As Far as I know Apache runs as root too(PLESK 11).
FindBin.pm is located in the named dir and I already tried to set it to 777.
Try installing VMS::Filespec, which seems to be the module FindBin is trying to require.
On the shell:
cpanm VMS::Filespec
If that doesn't work (the command fails), then try first:
cpan App::cpanminus
...and then try the first command again.
HTH
Francisco

Error using bytecode-compiling filter, PERL

When I compile using: pp -I lib -f Bytecode -o myapp_binary_bytecode myapp
I get this error:
"my" variable $fh masks earlier declaration in same scope at /Library/Perl/5.12/PAR/Filter/Bytecode.pm line 60.
Can't locate B/Bytecode.pm in #INC (#INC contains: /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.3/darwin-thread-multi-2level /Library/Perl/Updates/5.12.3 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at (eval 1) line 18.
BEGIN failed--compilation aborted at (eval 1) line 18.
BEGIN failed--compilation aborted.
Cannot transform /var/folders/cd/rwsp63c15bb01r89z76_bvr40000gn/T/Q3ubgSUe8P to /var/folders/cd/rwsp63c15bb01r89z76_bvr40000gn/T/LIcOpNf_Oh: No such file or directory (512)
Although the compiled binary works, but how can I fix the error?
Thanks!
The error says you're trying to use a module Perl can't locate. The usual cause is that you don't have that module installed.
A lack of permissions to read the module file could also lead to that error, but that's almost never the problem.
Unrelatedly, I would look into that my problem. As to why the running binary still has that problem, pp can easily miss dependencies, but it has a dynamic way to counter that problem. Try running pp -x script and it will run the script to find any run-time dependencies. Also I think there's a switch for manually adding dependencies to the list.