1

我有一个 Perl 脚本 test.pl,其中包括另一个 Perl 模块 fact.pm,它位于 crypt/Module 目录下。crypt/test.pl 的源代码是:

#!/usr/bin/perl
use Term::ANSIColor qw(:constants);
use File::Path;
use POSIX qw(strftime);
use File::Basename qw(dirname);
use Cwd  qw(abs_path);
use lib dirname(dirname abs_path $0);
use crypt::Module::fact qw(factorial);

&factorial();#function present in fact.pm
print("Thanks for that thought \n");

给出的 PAR 打包命令是

pp -M Module::fact -o test test.pl

在将可执行测试复制到不同的目录路径并执行它时,我收到以下错误:

Can't locate crypt/Module/fact.pm in @INC (you may need to install the crypt::Module::fact module)

如何将模块包含在可执行文件中?

4

1 回答 1

0

首先,我建议使用pp实用程序的 -c 和/或 -x 选项,它们用于“确定附加的运行时依赖项”。我已经养成了两者都用的习惯。

尽管您使用 -M 选项来添加模块,但我认为您对该选项有误。在您的代码中,您使用的是“crypt::Module::fact”模块,但您使用 -M 选项指定了“Module::fact”模块。也许如果您使用“-M crypt::Module::fact”而不是“-M Module::fact”,您的问题可能会得到解决。

此外,您可能需要使用 -I(或 -lib)来指定任何其他模块库目录的路径。

于 2016-03-07T06:47:53.257 回答