解决 Net::ZooKeeper找不到动态链接库符号问题
引用Net::ZooKeeper这个包,可能会报这个错误
Can‘t load ‘/usr/local/lib64/perl5/auto/Net/ZooKeeper/ZooKeeper.so‘ for module Net::ZooKeeper: /usr/local/lib64/perl5/auto/Net/ZooKeeper/ZooKeeper.so: undefined symbol: ZOO_PERM_CREATE at /usr/lib64/perl5/XSLoader.pm line 70. at /usr/local/lib64/perl5/Net/ZooKeeper.pm line 109.
查看XSLoader.pm的70行:
70 my $libref = dl_load_file($file, 0) or do { 71 require Carp; 72 Carp::croak("Can‘t load ‘$file‘ for module $module: " . dl_error()); 73 };
实际上是加载ZooKeeper.so这个动态链接库。我们objdump,看看这个缺少的符号到底有没有在这个链接库里面。
[zhangbin@localhost xoa2-perl]$ objdump -x /usr/local/lib64/perl5/auto/Net/ZooKeeper/ZooKeeper.so | grep ZOO 0000000000000000 *UND* 0000000000000000 ZOO_PERM_CREATE 0000000000000000 *UND* 0000000000000000 ZOO_READ_ACL_UNSAFE 0000000000000000 *UND* 0000000000000000 ZOO_PERM_WRITE 0000000000000000 *UND* 0000000000000000 ZOO_ASSOCIATING_STATE 0000000000000000 *UND* 0000000000000000 ZOO_CREATED_EVENT 0000000000000000 *UND* 0000000000000000 ZOO_CONNECTED_STATE 0000000000000000 *UND* 0000000000000000 ZOO_AUTH_FAILED_STATE 0000000000000000 *UND* 0000000000000000 ZOO_EPHEMERAL 0000000000000000 *UND* 0000000000000000 ZOO_SEQUENCE 0000000000000000 *UND* 0000000000000000 ZOO_PERM_READ 0000000000000000 *UND* 0000000000000000 ZOO_CREATOR_ALL_ACL 0000000000000000 *UND* 0000000000000000 ZOO_PERM_ALL 0000000000000000 *UND* 0000000000000000 ZOO_DELETED_EVENT 0000000000000000 *UND* 0000000000000000 ZOO_OPEN_ACL_UNSAFE 0000000000000000 *UND* 0000000000000000 ZOO_PERM_ADMIN 0000000000000000 *UND* 0000000000000000 ZOO_CONNECTING_STATE 0000000000000000 *UND* 0000000000000000 ZOO_EXPIRED_SESSION_STATE 0000000000000000 *UND* 0000000000000000 ZOO_NOTWATCHING_EVENT 0000000000000000 *UND* 0000000000000000 ZOO_PERM_DELETE 0000000000000000 *UND* 0000000000000000 ZOO_CHANGED_EVENT 0000000000000000 *UND* 0000000000000000 ZOO_CHILD_EVENT 0000000000000000 *UND* 0000000000000000 ZOO_SESSION_EVENT
标记为UND,说明这是一个外部符号,应该是需要引用其他库,估计是zookeeper库。但是lib包已经加入了LD_LIBRARY_PATH,非常奇怪。
尝试重新编译ZooKeeper.so(源码在zookeeper的contrib/zkperl下),发现发布包是用MakeMaker组织的,首先生成Makefile,获得下面的提示:
[zhangbin@localhost zkperl]$ perl Makefile.PL Warning (mostly harmless): No library found for -lzookeeper_mt Generating a Unix-style Makefile Writing Makefile for Net::ZooKeeper Writing MYMETA.yml and MYMETA.json
注意第一行的warning,这是解决问题的关键。Most harmless,but harm this time。查看 Makefile.PL的 第31行
31 GetOptions( 32 ‘zookeeper-include=s‘ => \@zk_inc_paths, 33 ‘zookeeper-lib=s‘ => \@zk_lib_paths 34 );
可见第二个选项是必须的。
重新编译。
[zhangbin@localhost zkperl]$ perl Makefile.PL --zookeeper-lib=/home/zhangbin/env/lib Checking if your kit is complete... Looks good Generating a Unix-style Makefile Writing Makefile for Net::ZooKeeper Writing MYMETA.yml and MYMETA.json
然后make && sudo make install。问题解决。
可能XSLoader没有自动从LD_LIBRARY_PATH寻找可用的库和符号表的机制。
本文出自 “新青年” 博客,请务必保留此出处http://luckybins.blog.51cto.com/786164/1613660
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。