Brighid McDonnell
Brighid McDonnell

Reputation: 4343

Perl can't find a module that is in @INC

I'm writing a Perl module on my OS X 10.7 Mac, and I'm running into an error with the DBI module when I try to use it. I was able to separate the problem from my module and reproduce it with just this:

[sean@mac:~]$ perl -e 'use DBI;'
Can't locate DBI.pm in @INC (@INC contains:
    /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level
    /opt/local/lib/perl5/site_perl/5.12.4
    /darwin-multi-2level
    /opt/local/lib/perl5/site_perl/5.12.4
    /opt/local/lib/perl5
    /vendor_perl/5.12.4/darwin-multi-2level
    /opt/local/lib/perl5/vendor_perl/5.12.4
    /opt/local/lib/perl5/5.12.4/darwin-multi-2level
    /opt/local/lib/perl5/5.12.4
    /opt/local/lib/perl5/site_perl
    /opt/local/lib/perl5/vendor_perl .) at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

The reason this is puzzling is this:

[sean@mac:~]$ find /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level -iname '*dbi*' -maxdepth 2
  /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level/auto/DBI
  /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level/Bundle/DBI.pm
  /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level/DBI
  /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level/DBI.pm
  /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level/dbixs_rev.pl

There is a DBI folder and a DBI.pm module right where Perl is supposed to look! Why is it the case that a file which is present in a path that's included in @INC, is not found by Perl?

I was able to find a workaround by twisting Perl's arm: when I add a use lib '/System/Library/Perl/Extras/5.12/darwin-thread-multi-2level'; line to my module, Perl appears to find DBI correctly. However, in this case, perl -d foo.pm results in the following:

  dyld: lazy symbol binding failed: Symbol not found: _Perl_Gthr_key_ptr
    Referenced from: /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level/auto/DBI/DBI.bundle
    Expected in: flat namespace

  dyld: Symbol not found: _Perl_Gthr_key_ptr
    Referenced from: /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level/auto/DBI/DBI.bundle
    Expected in: flat namespace

  Trace/BPT trap: 5

I don't know how to interpret that either, and so I'm not satisfied with my workaround - it still has the smell of "there is an underlying problem that will become a nasty surprise in the future if you don't figure it out."

Why is DBI not importing correctly, and what does the "lazy symbol binding" debug message mean?

Upvotes: 2

Views: 5324

Answers (1)

AndrewPK
AndrewPK

Reputation: 6150

This is often a problem I have when using multiple versions of perl and modules getting compiled for one version, and then not working for another but still sitting in @INC (my own mistake for not setting a local::lib path for each perl sometimes -- just ran into this problem with EV the other day due to my forgetfulness).

Best way to test is to (backup the current module) remove the module from the @INC path, and try re-compiling it again to see if that solves the problem.

I recommend cpanm for your cpan and perl module installing needs :)

Upvotes: 1

Related Questions