在我的Perl脚本中使用Net::SSH2模块,并尝试使用Par::P acker制作可执行文件(.exe用于Windows(。该脚本需要使用公钥从 Windows 框 ssh 到 linux 框,并且不想输入密码。
运行.exe时面临以下错误
无法加载 'C:\Users...\AppData\Local\Temp\par-73656172756d7567616d\cache-a6d57d5a234829aae84d08c4a78a09ad307ea8d3\a9057da2.xs.dll' 对于模块 Net::SSH2: load_file:指定的模块不能 在 C:/Strawberry/perl/lib/DynaLoader.pm 第 193 行找到。在 C:/Strawberry/perl/vendor/lib/PAR/Heavy.pm 第 123 行。
尝试使用以下方法进行解决方法,但没有一种有效
- 尝试从Strawberry Perl的便携式版本打包
- 尝试链接 a9057da2.xs.dll同时使用 Par::P acker 打包
是否有任何解决方法或修复程序可以将perl scrip打包到Net:SSH2中.exe。 或者是否有Net::SSH2的替代方案,用于使用公钥(不传递密码(从Windows到Linux的ssh?
如果你得到类似的东西:
Can't load D:TEMPpar-76696b616d7768cache-48ca417d0c47dd7f7245a1218d8d6614470afa937c34139c.xs.dll' for module XML::LibXML: load_file:The specified module could not be found at <embedded>/DynaLoader.pm line 193.
at <embedded>/PAR/Heavy.pm line 140.
BEGIN failed--compilation aborted at D:TEMPpar-76696b616d7768cache-48ca417d0c47dd7f7245a1218d8d6614470afa93inclib/XML/LibXML.pm line 156.
Compilation failed in require at script/test.pl line 3.
BEGIN failed--compilation aborted at script/test.pl line 3.
然后添加以下测试代码
(检查您的 Listdlls 路径.exe并根据需要修复以下内容(
#This is the code causing the issue
use XML::LibXML;
my $x = XML::LibXML->new();
ListPerlDLLs();
sub ListPerlDLLs
{
my @ret = `C:\"Program Files"\Sysinternals\Listdlls.exe $$`; # $$ : current PID
foreach my $line (@ret)
{
$line =~ s/s$//;
next if $line !~ /^0xw+s+w+s+(.+)/;
my $dll = $1;
next if $dll =~ /^c:\windows\/i;
print "$dlln";
}
}
Listdlls.exe 来自 Microsoft - 参见SysInternals\
首先,双击 Listdlls.exe 接受免责声明
(将在首次启动时请求批准(。
当你运行Perl脚本时,你会得到这样的东西:
D:/strawberry-perl/perl/bin/perl.exe
D:/strawberry-perl/perl/bin/perl532.dll
D:/strawberry-perl/perl/bin/libgcc_s_seh-1.dll
D:/strawberry-perl/perl/bin/libwinpthread-1.dll
D:/strawberry-perl/perl/bin/libstdc++-6.dll
D:/strawberry-perl/perl/lib/auto/Encode/Encode.xs.dll
D:/strawberry-perl/perl/lib/auto/Fcntl/Fcntl.xs.dll
D:/strawberry-perl/perl/lib/auto/Storable/Storable.xs.dll
D:/strawberry-perl/perl/lib/auto/Data/Dumper/Dumper.xs.dll
D:/strawberry-perl/perl/lib/auto/IO/IO.xs.dll
D:/strawberry-perl/perl/vendor/lib/auto/XML/LibXML/LibXML.xs.dll
D:/strawberry-perl/c/bin/libxml2-2__.dll
D:/strawberry-perl/c/bin/libiconv-2__.dll
D:/strawberry-perl/c/bin/liblzma-5__.dll
D:/strawberry-perl/c/bin/zlib1__.dll
D:/strawberry-perl/perl/lib/auto/List/Util/Util.xs.dll
如果您构建并运行 EXE,您将获得类似以下内容的内容:
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/test.exe
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/perl532.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/libgcc_s_seh-1.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/libwinpthread-1.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/libstdc++-6.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/5461bd7b.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/1ed3ae5b.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/89b9c18b.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/18f23f26.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/0e796a00.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/5d0ea4ea.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/d3d27bc6.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/d8bcc032.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/64916f0f.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/76c6a0cc.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/6b1ff21f.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/4eceebd6.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/ebaed210.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/831f407e.xs.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/7c34139c.xs.dll
D:/strawberry-perl/c/bin/libxml2-2__.dll
D:/strawberry-perl/c/bin/liblzma-5__.dll
D:/strawberry-perl/c/bin/zlib1__.dll
D:/strawberry-perl/c/bin/libiconv-2__.dll
最后四个是缺少的DLL -
使用--link
参数添加它们:
call pp test.pl -o test.exe --link D:/strawberry-perl/c/bin/libxml2-2__.dll --link D:/strawberry-perl/c/bin/liblzma-5__.dll --link D:/strawberry-perl/c/bin/zlib1__.dll --link D:/strawberry-perl/c/bin/libiconv-2__.dll
可能您没有将libssh2
和openssl
DLL 打包到可执行文件中。
Par::Packer
不会自动检测 DLL 依赖项,则需要明确告诉它程序需要哪些依赖项(发现程序需要哪些 DLL 的一种简单方法是使用进程监视器,这是一个允许监视进程活动的实用程序(。
另一种选择是使用我的模块 Win32::P acker 打包会自动查找 DLL 依赖项的应用程序。