6

My new M1-based Mac has Apple's built-in Perl version, v5.28.2. I used homebrew to install the latest perl, 5.32.0, and I configured the local::lib option so that cpan modules would get installed in ~/perl5. All of that works for the most part.

But... I cannot install XML:Parser in this homebrew/local-lib configuration. I think XML::Parser is installed in Apple's base config, but I really want to be able to update Perl and install modules, so I think this config is the right way to do that. But a LOT of stuff requires XML::Parser.

Here are my environment variables, PATH, etc:

PERL5LIB=/Users/jim/perl5/lib/perl5
PERL_LOCAL_LIB_ROOT=/Users/jim/perl5
PERL_MB_OPT=--install_base "/Users/jim/perl5"
PERL_MM_OPT=INSTALL_BASE=/Users/jim/perl5

PATH=/Users/jim/perl5/bin:.:/Users/jim/Documents/scripts:/opt/homebrew/bin:/Developer/usr/bin:/System/Library/Frameworks/Python.framework/Versions/Current/bin:/Users/jim/Library/Python/2.7/bin:/Users/jim/perl5/bin:/Users/jim/go/bin:/Users/jim/.cargo/bin:/usr/local/bin:/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11/bin

% /usr/bin/which -a perl
/opt/homebrew/bin/perl
/usr/bin/perl

% /usr/bin/which -a cpan
/Users/jim/perl5/bin/cpan
/opt/homebrew/bin/cpan
/Users/jim/perl5/bin/cpan
/usr/bin/cpan

Running cpan install XML::Parser gives:

Running make test for TODDR/XML-Parser-2.46.tar.gz
"/opt/homebrew/Cellar/perl/5.32.0/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Expat.bs ../blib/arch/auto/XML/Parser/Expat/Expat.bs 644
Manifying 1 pod document
PERL_DL_NONLAZY=1 "/opt/homebrew/Cellar/perl/5.32.0/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/astress.t ........... 1/27
    Can't load '/Users/jim/.cpan/build/XML-Parser-2.46-0/blib/arch/auto
    /XML/Parser/Expat/Expat.bundle' for module XML::Parser::Expat:
    dlopen(/Users/jim/.cpan/build/XML-Parser-2.46-0/blib/arch/auto
    /XML/Parser/Expat/Expat.bundle, 2): Symbol not found: _XML_DefaultCurrent
  Referenced from: /Users/jim/.cpan/build/XML-Parser-2.46-0/blib/arch/auto/XML/Parser/Expat/Expat.bundle
  Expected in: flat namespace
 in /Users/jim/.cpan/build/XML-Parser-2.46-0/blib/arch/auto/XML/Parser/Expat/Expat.bundle at /opt/homebrew/Cellar/perl/5.32.0/lib/perl5/5.32.0/darwin-thread-multi-2level/DynaLoader.pm line 197.
 at /Users/jim/.cpan/build/XML-Parser-2.46-0/blib/lib/XML/Parser.pm line 18.
Compilation failed in require at /Users/jim/.cpan/build/XML-Parser-2.46-0/blib/lib/XML/Parser.pm line 18.
BEGIN failed--compilation aborted at /Users/jim/.cpan/build/XML-Parser-2.46-0/blib/lib/XML/Parser.pm line 22.
Compilation failed in require at t/astress.t line 11.
BEGIN failed--compilation aborted at t/astress.t line 11.
t/astress.t ........... Dubious, test returned 2 (wstat 512, 0x200)
Failed 27/27 subtests 

(Line breaks added to error message to make it readable.)

There are more test failures after that, but that's the root of the problem there, I think.

Any suggestions?

ikegami
  • 367,544
  • 15
  • 269
  • 518
jimtut
  • 2,366
  • 2
  • 16
  • 37
  • BTW, I've removed all the local-lib stuff in one shell, testing by installing a simple CPAN module, and saw it get installed in the homebrew area. Immediately tried to install XML::Parser, and get the same error. So, I don't think it's related to local-lib stuff at all, just a combination of homebrew, this module's code, and maybe other stuff on the Mac (which is new, and only has ARM-based open-source SW installed, no legacy x86 stuff). – jimtut Dec 20 '20 at 18:54
  • 1
    Another BTW: I said in the original question that I "think" XML::Parser is installed in Apple's Perl. I should say that I *know* it's installed - I can clearly see it in `/System/Library/Perl/Extras/5.18/darwin-thread-multi-2level/XML/Parser.pm`. And a simple `/usr/bin/perl -e "use XML::Parser"` works fine. Strangely, though that directory is NOT part of my @INC (which I checked), and that XML::Parser is under a 5.18 dir, not 5.28. Not sure how it's working under Apple's install w/ that strange config, but just wanted to clarify that point above. The main question is still about homebrew. – jimtut Dec 20 '20 at 19:59
  • 2
    I am on macOS 11.1 Big Sur, using perlbrew with perl version 5.30.1. I tried `cpanm XML::Parser` and the tests failed with the same error as you describe: `Symbol not found: _XML_DefaultCurrent`. However, I then tried the fix in [Make DynaLoader on MacOS check library existence with dlopen](https://github.com/Perl/perl5/pull/18407) and here `XML::Parser` installed fine. – Håkon Hægland Dec 20 '20 at 20:03
  • 2
    Big Sur changed things, and it broke one of Perl's module-installers. The result is that that `-lexpat` ends up not being used (and you probably got a very incorrect warning claiming this is "probably harmless"), so XML::Parser::Expat (part of XML::Parser) isn't linked to the C library it needs, so it fails. – ikegami Dec 20 '20 at 20:09
  • @ikegami *"The result is that that -lexpat ends up not being used"* yes that seems to be the case. I downloaded XML-Parser-2.46.tar.gz and run `perl Makefile.PL; make` (using perl 5.30.1 from perlbrew). The output showed that `cc -mmacosx-version-min=10.15 -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector-strong Expat.o -o ../blib/arch/auto/XML/Parser/Expat/Expat.bundle` was used to generate the shared object. If I added manually `-lexpat` to the end of the previous command and executed it and then ran `make test` all the tests passed here. – Håkon Hægland Dec 21 '20 at 05:41
  • @jmtut Which version of macOS are you using? – Håkon Hægland Dec 21 '20 at 05:41
  • @HåkonHægland they said it's an M1, so that makes it Big Sur, right? – ikegami Dec 21 '20 at 06:10
  • @ikegami *"they said it's an M1"* Ok, great then OP is probably having the same issue as I have. I tried `perl Makefile.PL; make` with perl 5.33.5 and can confirm that this version adds `-lexpat` so this explains why it works with that version. But I cannot find the actual commit that implements the fix yet.. I thought it would be in [PR 18407](https://github.com/Perl/perl5/pull/18407) but maybe it was fixed earlier – Håkon Hægland Dec 21 '20 at 06:31
  • @HåkonHægland For sure. My earlier comment was an explanation of yours. – ikegami Dec 21 '20 at 06:32
  • @HåkonHægland Didn't you build your 5.33.5 using `git fetch origin pull/18407/head:bigsur3`? – ikegami Dec 21 '20 at 06:38
  • @ikegami Yes I did – Håkon Hægland Dec 21 '20 at 06:40
  • @HåkonHægland So yeah, it's PR 18407 – ikegami Dec 21 '20 at 07:16
  • @jimtut [This is the problem](https://stackoverflow.com/q/65297237/589924). I'm not closing as a dup cause it might be possible to hack things so you can install your module, but that's beyond my means having no access to a Mac. (Not sure how you managed to get Perl installed at all.) – ikegami Dec 21 '20 at 07:19
  • 1
    Sorry, folks, I was sleeping when all these great comments were coming in. Yes, I’m running Big Sur. Perl was installed via Homebrew under 11.0 (no problems, and its running fine as a native (ARM) executable. I’ve since upgraded to 11.1, and that was the first time I tried to install XML::Parser. I will try your suggestions tonight! – jimtut Dec 21 '20 at 13:06
  • Thanks for all the comments and help - I love this community! I accepted Leon's answer as it was the most straight-forward way to accomplish my goal (and it was the only actual answer), but I appreciate all the work you folks do here and keeping Perl running! :-) – jimtut Dec 21 '20 at 20:14

1 Answers1

6

Installing the latest beta release of ExtUtils::MakeMaker (7.57_02) should solve your problem. It will probably be released as a stable release soon.

ETA: 7.58 has now been released.

Leon Timmermans
  • 30,029
  • 2
  • 61
  • 110
  • 1
    According to my tests on Big Sur (see comment above) the fix was to add `-lexpat` to the linker flags. What part (commit) of [that release](https://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker/commits/master) introduces (adds back) the `-lexpat` linker flag for `Makefile`? – Håkon Hægland Dec 21 '20 at 18:51
  • 2
    The change to ExtUtils::Liblist::Kid (8b924f65 and 21a441da) – Leon Timmermans Dec 21 '20 at 19:03
  • Thanks, I see it now, `DynaLoader::dl_load_file()` is used to verify that the library exists. – Håkon Hægland Dec 21 '20 at 19:16