Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi Monks,

First (registered) post. This is a bit of a long one--I was thinking things through while typing it up, which I hope helps you.

I have a Mac running 10.6.8. I have the system perl /usr/bin/perl (5.10.0), and also a MacPorts perl /opt/local/bin/perl (5.14.2), the latter is the first in my $PATH. Until recently I had used CPAN to install non-MacPorts modules into the MacPorts tree /opt/local/lib/perl5/site_perl/. That was OK, but I was told that it was a bad idea to have things in the MacPorts tree that MacPorts doesn't know about, so I recently deleted everything there and reinstalled in my home dir /Users/derek/local/lib/perl5. I put export PERL5LIB="/Users/derek/local/lib/perl5" into my ~/.profile, added INSTALL_BASE=/Users/derek/local to the config options in cpan (makepl_arg and similarly for mbuildpl_arg) and I thought all was well. (yes, I'm aware of local::lib, but don't have it installed.)

Now I am checking some code in the PDL test harness, and the code does image format conversion by calling some netpbm programs (in this case, 'pnmquant'). Some of these are Perl scripts themselves. They start with #!/usr/bin/perl. And I am getting some failures that I think I understand and some I don't, so I wanted to get some outside advice at this point. For the rest of this post, please remember that I have now undefined the $PERL5LIB environment variable, for clarity. The test image is named img.pnm

When I run from the command line
pnmquant 256 img.pnm
It produces the expected output. But when I set that PERL5LIB variable:
PERL5LIB=/Users/derek/local/lib/perl5 pnmquant 256 img.pnm, I get a Segmentation fault. That is bad, because that line (I think) emulates best the environment I will normally be running under. If I try to run under the debugger, I get
PERL5LIB=/Users/derek/local/lib/perl5 /opt/local/bin/perl -d /opt/local/bin/pnmquant 256 img.pnm success or
PERL5LIB=/Users/derek/local/lib/perl5 /usr/bin/perl -d /opt/local/bin/pnmquant 256 img.pnm failure depending on the perl used. The latter debugger fails immediately with

dyld: Symbol not found: _Perl_xs_apiversion_bootcheck Referenced from: /Users/derek/local/lib/perl5/darwin-thread-multi-2l +evel/auto/Term/ReadKey/ReadKey.bundle Expected in: flat namespace Trace/BPT trap

If I prepend VERSIONER_PERL_PREFER_32_BIT=no to that line as recommended in this post I get the same dyld error. That post suggested that modules compiled for different perl versions different from the running perl (specifically 32- vs 64-bit) were the culprit. But I don't think that's the case here. I think it's that doing nm ReadKey.bundle |grep _Perl_xs_api on ~/local/lib/...../auto/Term/ReadKey/ReadKey.bundle returns that symbol and doing the same on the 5.10.0 .bundle (in /System/Library/.....etc) does not return that symbol.

If I instead prepend PERL_DL_NONLAZY=1 to the line, then I get no dyld error and the correct output. This may explain why the code in question does not fail when run under make test (which as you know sets that NONLAZY variable), but does when run under perl -Mblib t/testscript.t.

Question 1: Shouldn't PERL_DL_NONLAZY be helpfully causing these sorts of errors, not preventing them like it seems to be doing?

Question 2: Should my directory structure in ~/local/lib/perl5 have perl-version-specific directories, or is that something I would have had to create manually, or does that not matter in this case?

Question 3: The segfaulting seems to be caused because the PERL5LIB prepends a perl-5.14.2 directory to @INC, a and ReadKey.bundle are found there, but the perl 5.10 called by the script or by me manually sees a different symbol table in that .bundle file than it is expecting. How can I avoid that, what do you recommend for a path forward out of this mess? Let's assume I can't (or won't) change the Netpbm source code to have the perl scripts start with #!/usr/bin/env perl instead.


In reply to combination of multiple installed Perls and some environment variables cause segfaults by dlamb

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [Discipulus]: tybalt89 you must consider writing a book: The Perl regex approach to every problem

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (4)
    As of 2017-11-23 08:16 GMT
    Find Nodes?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:

      Results (331 votes). Check out past polls.