如何将 Perl DBI 模块的所有依赖项添加到 PAR 打包程序存档
How to add all dependencies of Perl DBI module to PAR packer archive
我创建了一个 Perl 脚本,它使用 DBI 包连接到 MySQL 数据库。为了在不一定安装所有依赖项的其他 linux 平台上使其成为 运行,我使用以下命令创建了一个独立文件,其中包含 Par Packer (pp) 的所有依赖项:
pp -c -x -o myscript myscript.pl
独立文件在创建它的机器上工作正常,但是,在其他机器上,我在执行 DBI -> connect() 的行收到以下错误。
install_driver(mysql) failed: Can't load '/tmp/par-6d756e7a/cache-44c3853ef3002ad860cfe135d24ccc8829af39da/89fc0e43.so' for module DBD::mysql: libmysqlclient.so.20: cannot open shared object file: No such file or directory at /usr/lib/x86_64-linux-gnu/perl/5.22/DynaLoader.pm line 187.
at /usr/local/share/perl/5.22.1/PAR/Heavy.pm line 123.
Compilation failed in require at (eval 15) line 3.
Perhaps a required shared library or dll isn't installed where expected
at DBI/DBHandler.pm line 41.
好像少了个文件,不知道怎么解决。添加 -lib=/tmp/par-6d756e7a/cache-44c3853ef3002ad860cfe135d24ccc8829af39da/89fc0e43.so
不起作用。
更新 1
发生错误的服务器上已经安装了以下库:
$ dpkg -l | grep mysql
ii libdbd-mysql-perl 4.028-2+deb8u2 amd64 Perl5 database interface to the MySQL database
ii libmysqlclient18:amd64 5.5.54-0+deb8u1 amd64 MySQL database client library
ii mysql-client 5.5.54-0+deb8u1 all MySQL database client (metapackage depending on the latest version)
ii mysql-client-5.5 5.5.54-0+deb8u1 amd64 MySQL database client binaries
ii mysql-common 5.5.54-0+deb8u1 all MySQL database common files, e.g. /etc/mysql/my.cnf
这是一个示例脚本:
#!/usr/bin/perl
use DBI;
my $dbh = DBI -> connect("dbi:mysql:homo_sapiens_core_89_38:ensembldb.ensembl.org:3306", "anonymous") || die "Connection Error: $DBI::errstr\n";
my $sth = $dbh -> prepare("SELECT * FROM exon limit 10");
my $success = $sth -> execute();
if (!$success && !defined $DBI::errstr){
print STDERR "Query not successful. No error message returned. Try to continue.\n";
}
elsif (!$success && defined $DBI::errstr){
die "SQL Error: $DBI::errstr\n";
}
while (my @row = $sth -> fetchrow_array){
print join("\t", @row)."\n";
}
$sth -> finish();
$dbh -> disconnect();
错误信息的以下部分:
libmysqlclient.so.20: cannot open shared object file: No such file or directory
...通常意味着 MySQL 客户端库未安装在您尝试 unpack/install 的系统上,因此您需要安装它。例如,在 Ubuntu:
sudo apt-get install mysql-client
我创建了一个 Perl 脚本,它使用 DBI 包连接到 MySQL 数据库。为了在不一定安装所有依赖项的其他 linux 平台上使其成为 运行,我使用以下命令创建了一个独立文件,其中包含 Par Packer (pp) 的所有依赖项:
pp -c -x -o myscript myscript.pl
独立文件在创建它的机器上工作正常,但是,在其他机器上,我在执行 DBI -> connect() 的行收到以下错误。
install_driver(mysql) failed: Can't load '/tmp/par-6d756e7a/cache-44c3853ef3002ad860cfe135d24ccc8829af39da/89fc0e43.so' for module DBD::mysql: libmysqlclient.so.20: cannot open shared object file: No such file or directory at /usr/lib/x86_64-linux-gnu/perl/5.22/DynaLoader.pm line 187.
at /usr/local/share/perl/5.22.1/PAR/Heavy.pm line 123.
Compilation failed in require at (eval 15) line 3.
Perhaps a required shared library or dll isn't installed where expected
at DBI/DBHandler.pm line 41.
好像少了个文件,不知道怎么解决。添加 -lib=/tmp/par-6d756e7a/cache-44c3853ef3002ad860cfe135d24ccc8829af39da/89fc0e43.so
不起作用。
更新 1
发生错误的服务器上已经安装了以下库:
$ dpkg -l | grep mysql
ii libdbd-mysql-perl 4.028-2+deb8u2 amd64 Perl5 database interface to the MySQL database
ii libmysqlclient18:amd64 5.5.54-0+deb8u1 amd64 MySQL database client library
ii mysql-client 5.5.54-0+deb8u1 all MySQL database client (metapackage depending on the latest version)
ii mysql-client-5.5 5.5.54-0+deb8u1 amd64 MySQL database client binaries
ii mysql-common 5.5.54-0+deb8u1 all MySQL database common files, e.g. /etc/mysql/my.cnf
这是一个示例脚本:
#!/usr/bin/perl
use DBI;
my $dbh = DBI -> connect("dbi:mysql:homo_sapiens_core_89_38:ensembldb.ensembl.org:3306", "anonymous") || die "Connection Error: $DBI::errstr\n";
my $sth = $dbh -> prepare("SELECT * FROM exon limit 10");
my $success = $sth -> execute();
if (!$success && !defined $DBI::errstr){
print STDERR "Query not successful. No error message returned. Try to continue.\n";
}
elsif (!$success && defined $DBI::errstr){
die "SQL Error: $DBI::errstr\n";
}
while (my @row = $sth -> fetchrow_array){
print join("\t", @row)."\n";
}
$sth -> finish();
$dbh -> disconnect();
错误信息的以下部分:
libmysqlclient.so.20: cannot open shared object file: No such file or directory
...通常意味着 MySQL 客户端库未安装在您尝试 unpack/install 的系统上,因此您需要安装它。例如,在 Ubuntu:
sudo apt-get install mysql-client