Perl - dyld:惰性符号绑定失败:找不到符号:_mysql_init

Perl - dyld: lazy symbol binding failed: Symbol not found: _mysql_init

我在执行需要 DBD::mysql 模块的 perl 脚本时遇到了第一次看到的消息。

简单示例:

use DBI;
 
my $dbh = DBI->connect("DBI:mysql:db",'root','root');

$dbh->disconnect();

我在 ARM64 上使用 macOS 11.1,我的 perl 版本是 5.30.3,安装了 perlbrew。

消息是:

dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from: /Users/test/perl5/perlbrew/perls/perl-5.30.3/lib/site_perl/5.30.3/darwin-2level/auto/DBD/mysql/mysql.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_init
  Referenced from: /Users/test/perl5/perlbrew/perls/perl-5.30.3/lib/site_perl/5.30.3/darwin-2level/auto/DBD/mysql/mysql.bundle
  Expected in: flat namespace

Abort trap: 6

知道如何解决这个问题吗?

在我的 .bash_profile.bashrc 中,我添加了这些行:

export PATH="/usr/local/mysql/bin:${PATH}"
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:${DYLD_LIBRARY_PATH}"

问题是新的 system integrity protection procedure,它导致 DYLD_LIBRARY_PATH 无法传播到子进程。具体来说,当 运行 make test 时,测试子进程不会从父 shell.

中获取 DYLD_LIBRARY_PATH

这个问题之前 reported

另见 this 问题。

最终解决了本机安装 mysql。我使用 brew 重新安装了它,并将 -s 传递给命令 (brew install -s mysql)。所以问题是错误的体系结构,现在也为 ARM64 重新编译它 make test,同时安装 DBD::mysql 工作正常,没有任何错误。

希望能有所帮助:)