Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Problem Installing Perl-Tk on macOS Monterey (12.6) with Apple M1 chip

by cmv (Chaplain)
on Oct 04, 2022 at 16:33 UTC ( [id://11147245]=perlquestion: print w/replies, xml ) Need Help??

cmv has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks- EDIT: Please see inline UPDATE and UPDATE 2 below...

I've been away from both Perl and the Monastery for some time now, and am delighted to be getting back in the swing of things!

My first goal is to get working Perl with Perl-Tk up and running on my M1 Mac mini, running macOS Monterey (12.6).

Taking the path of least resistance, I decided to use perlbrew to get me started. Everything worked great, but the CPAN install of pTk hangs forever on one of the first tests.

Here is a summary of how I got there:

# Install Homebrew (from https://brew.sh) $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebre +w/install/HEAD/install.sh)" # Use Homebrew to install some stuff MacOSx doesn't normally have: $ brew install wget $ brew install tcl-tk # Needed due to apple's old, buggy, version $ brew install tkdiff $ brew install gawk $ brew install perl $ brew install --cask xquartz # Needed for X11 on Mac # Use CPAN shell to install perl modules $ /opt/homebrew/bin/perl -MCPAN -e shell install Term::ReadLine::Perl install CPAN reload CPAN install YAML install Tk

At this point the Tk testing failed with these messages:

... /Library/Developer/CommandLineTools/usr/bin/make all-am make[3]: Nothing to be done for `all-am'. make[2]: Nothing to be done for `all'. make[2]: Nothing to be done for `test_dynamic'. make[2]: Nothing to be done for `test_dynamic'. "/opt/homebrew/Cellar/perl/5.36.0/bin/perl" "-I../t" "-MTkTest" "-e" " +checked_test_harness('../xt', 0, '../blib/lib', '../blib/arch')" t/*. +t t/basic.t .. Failed 4/5 subtests t/crash.t .. Failed 1/1 subtests Test Summary Report ------------------- t/basic.t (Wstat: 11 (Signal: SEGV) Tests: 1 Failed: 0) Non-zero wait status: 11 Parse errors: Bad plan. You planned 5 tests but ran 1. t/crash.t (Wstat: 11 (Signal: SEGV) Tests: 0 Failed: 0) Non-zero wait status: 11 Parse errors: Bad plan. You planned 1 tests but ran 0. Files=2, Tests=1, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.09 cusr + 0.01 csys = 0.11 CPU) Result: FAIL Failed 2/2 test programs. 0/1 subtests failed. make[1]: *** [test_dynamic] Error 255 make: *** [subdirs-test_dynamic] Error 2 SREZIC/Tk-804.036.tar.gz /usr/bin/make test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports SREZIC/Tk-804.036.tar.gz Failed during this command: SREZIC/Tk-804.036.tar.gz : make_test NO

Somewhere in the output, it complained about DistnameInfo needing to be installed, so I did that, then tried installing Tk again, and it hangs on one of the first tests in an infinite loop:

install CPAN::DistnameInfo ... install Tk ... /Library/Developer/CommandLineTools/usr/bin/make all-am make[3]: Nothing to be done for `all-am'. make[2]: Nothing to be done for `all'. make[2]: Nothing to be done for `test_dynamic'. make[2]: Nothing to be done for `test_dynamic'. "/opt/homebrew/Cellar/perl/5.36.0/bin/perl" "-I../t" "-MTkTest" "-e" " +checked_test_harness('../xt', 0, '../blib/lib', '../blib/arch')" t/*. +t t/basic.t .. 1/5

Looking at the process, it's continuously using up 100% of a single core:

ID COMMAND %CPU TIME #TH #WQ #PORTS MEM PURG 47971 perl 99.7 37:19.27 1/1 0 10 15M 0B

My guess at what is happening here...

This is completely wrong, the installed tcl-tk does not seem to impact this at all

I'm suspecting that the old buggy version of tcl-tk that is shipped by Apple, is somehow causing this. I would like for the newer, working version of tcl-tk that I installed via Homebrew to be used, but I don't know how to specify that.

FYI: When I first installed tkdiff and ran it, things were all hosed up and it wasn't until I installed the newer, working version of tcl-tk that fixed the problem. I'm guessing that pTk is having the same issue as well.

Any pointers or help is much appreciated!

Thanks

-Craig

Replies are listed 'Best First'.
Re: Problem Installing Perl-Tk on macOS Monterey (12.6) with Apple M1 chip
by bliako (Monsignor) on Oct 05, 2022 at 07:40 UTC

    Firstly, check to see if perlbrew's perl is the one being used (as well as cpan) and not system perl: which perl; which cpan.

    Secondly, check to see if the modules you installed via perlbrew's cpan/cpanm do install in their proper locations and that the correct modules are loaded (where "incorrect" modules are those loaded from system perl's INC places). Useful here is the @INC : perl -e 'print "@INC"'

    Thirdly, the other interference from system perl+tk would be that their binary libraries (.so, .dylib) are loaded instead of perlbrew's perl+tk. You can check/affect that with the env vars: LD_LIBRARY_PATH and DYLD_LIBRARY_PATH and, better, sieve through the output of strace perl (consequently: strace /Library/Developer/CommandLineTools/usr/bin/make  all-am (note: I am not sure if this command will recursively strace all the calls inside the Makefile).

    I think with the above you can detect where libraries and modules are loaded from, and, therefore, eliminate the possibility of "interference" from system perl+tk.

    Using an older macOS is a bless and a curse: the newer (13.+) are locking the system with the so-called SIP with a really annoying effect: (DY)LD_LIBRARY_PATH env vars are *forbidden* (by the cupertino directorate) to be passed to executables, so this DYLD_LIBRARY_PATH=my-good-tk-libraries make all-am will have no effect and still be looking in /usr/lib first. The curse of course is that nothing works and the one daring to use older hardware feels like a leper, not least by the various forums' support.

    bw, bliako

      In the original post, you can see that I call the correct cpan using the perlbrew cpan full path name, which was built using the perlbrew perl, so I expected that all to work correctly.

      However, running which perl; which cpan from my command line shows me the system commands being found first. I will try fixing this so that perlbrew commands are in my environment first and see if that helps.

      Also, checking where the modules were installed shows the following:

      /opt/homebrew/Cellar/perl/5.36.0/bin/perl -e 'print "@INC"' /opt/homebrew/opt/perl/lib/perl5/site_perl/5.36/darwin-thread-multi-2l +evel /opt/homebrew/opt/perl/lib/perl5/site_perl/5.36 /opt/homebrew/op +t/perl/lib/perl5/5.36/darwin-thread-multi-2level /opt/homebrew/opt/pe +rl/lib/perl5/5.36 /opt/homebrew/lib/perl5/site_perl/5.36/darwin-threa +d-multi-2level /opt/homebrew/lib/perl5/site_perl/5.36

      There are no environment variables in my shell for LD_LIBRARY_PATH or DYLD_LIBRARY_PATH but maybe cpan adds them somehow?

      I will try using strace and see if the output indicates if the old system tcl-tk libraries are being used and post the results here.

UPDATE: Problem Installing Perl-Tk on macOS Monterey (12.6) with Apple M1 chip
by cmv (Chaplain) on Oct 05, 2022 at 17:35 UTC
    UPDATE: I created my own private copy of basic.t and added some stderr debugging statements, then tried running it by hand from the PNG directory. Ran it many times, and it mostly fails with a segmentation fault, but it also will sometimes hang as I said before. Here is an example of when it segfaults:
    $ cd /Users/cmv/.cpan/build/Tk-804.036-0/PNG $ /opt/homebrew/Cellar/perl/5.36.0/bin/perl -w t/cmv.t 1..5 ok 1 - use Tk::PNG; Photo 1 zsh: segmentation fault /opt/homebrew/Cellar/perl/5.36.0/bin/perl -w +t/cmv.t

    Here are some relavent lines from my cmv.t file

    ... use_ok('Tk::PNG'); my $file = (@ARGV) ? shift : "$FindBin::RealBin/../pngtest.png"; my $mw = MainWindow->new; $mw->geometry('+10+10'); $mw->update; #### Added by --cmv sleep 10; { print STDERR "Photo 1\n"; #### Added by --cmv my $image = $mw->Photo('-format' => "png", -file => $file); print STDERR "Photo 2\n"; #### Added by --cmv ok($image, "Loaded PNG image from $file"); print STDERR "Photo 3\n"; #### Added by --cmv $mw->Label(-image => $image)->pack; print STDERR "Photo 4\n"; #### Added by --cmv $mw->update; print STDERR "Photo 5\n"; #### Added by --cmv } ...

    Note 1: The $mw->update; line does cause the Tk mainwindow to show up on my screen!!!

    Note 2: The problem seems to be loading the PNG photo. More digging needed here.

    Many thanks to all who have provided pointers and help!

    -Craig

      I have verified that this is only an issue with the PNG code provided as part of pTk. I was able to manually run tests on all the rest of the pTk code, which was almost 100% successful, but have not yet had the time to nail down the specific cause of this PNG issue.

      Here is where I'm currently at:

      The offending line, causing the segfault, in the basic.t test file is:

      my $image = $mw->Photo('-format' => "png", -file => $file);
      Where:
      file="~/.cpan/build/Tk-804.036-0/PNG/t/../pngtest.png"

      When a segmentation fault occurs on a Mac, a *.ips file is created in ~/Library/Logs/DiagnosticReports providing more details on the fault. Stack frame analysis from this data yields:

      "frames":[
      {"imageOffset":9468,"symbol":"_longjmp","symbolLocation":72,"imageIndex":0}, {"imageOffset":18446639227543793010,"imageIndex":1}, {"imageOffset":166568,"symbol":"png_error","symbolLocation":420,"imageIndex":2}, {"imageOffset":91072,"symbol":"png_create_read_struct_2","symbolLocation":636,"imageIndex":2}, {"imageOffset":90424,"symbol":"png_create_read_struct","symbolLocation":60,"imageIndex":2}, {"imageOffset":10552,"symbol":"ChnReadPNG","symbolLocation":112,"imageIndex":2}, {"imageOffset":419820,"symbol":"ImgPhotoConfigureMaster","symbolLocation":1176,"imageIndex":3}, {"imageOffset":398084,"symbol":"ImgPhotoCreate","symbolLocation":204,"imageIndex":3}, {"imageOffset":366856,"symbol":"Tk_ImageObjCmd","symbolLocation":1664,"imageIndex":3}, {"imageOffset":88836,"symbol":"Call_Tk","symbolLocation":624,"imageIndex":3}, {"imageOffset":133540,"symbol":"XStoImage","symbolLocation":608,"imageIndex":3}, {"imageOffset":752088,"symbol":"Perl_pp_entersub","symbolLocation":1696,"imageIndex":4}, {"imageOffset":712144,"symbol":"Perl_runops_standard","symbolLocation":32,"imageIndex":4}, {"imageOffset":157920,"symbol":"S_run_body","symbolLocation":116,"imageIndex":4}, {"imageOffset":157800,"symbol":"perl_run","symbolLocation":648,"imageIndex":4}, {"imageOffset":15952,"symbol":"main","symbolLocation":180,"imageIndex":5}, {"imageOffset":20620,"symbol":"start","symbolLocation":520,"imageIndex":6}
      As you can see we did hit png_error() before heading to imagIndex(), then to _longjmp, which I'm guessing is the cause of the segfault.

      Since I'm not currently using PNG images for anything in my code, I just stubbed out the two test files and installed pTk via CPAN as you normally would. Everything else seems to be working fine.

      I would like to eventually figure out why this code segfaults on macOS Monterey (12.6) with Apple M1 chip, and feedback to the PNG group on what needs to be fixed.

      Any suggestions on what to try next would be welcome!

      Thanks

      -Craig

Re: Problem Installing Perl-Tk on macOS Monterey (12.6) with Apple M1 chip
by Anonymous Monk on Oct 05, 2022 at 10:20 UTC
    Tk.pm doesnt depend on tcl-tk

    if a test is failing, run the file individually, and identify the file for us

    dot dot dot isnt a full path name ;)

      Here is the relavent pstree output for the hanging processes:

      ... \-+= 03627 cmv /Library/Developer/CommandLineTools/usr/bin/make + test \-+- 05377 cmv /bin/sh -c cd PNG && make test_dynamic LIBPERL +_A="libperl.a" LINKTYPE="dynamic" OPTIMIZE="-O3" PREFIX="/opt/homebre +w/opt/perl" PASTHRU_DEFINE=' ' PASTHRU_INC='-I/usr/X11R6/include -I/o +pt/X11/include/freetype2 ' \-+- 05378 cmv /Library/Developer/CommandLineTools/usr/bin/ +make test_dynamic LIBPERL_A=libperl.a LINKTYPE=dynamic OPTIMIZE=-O3 P +REFIX=/opt/homebrew/opt/perl PASTHRU_DEFINE= PASTHRU_INC=-I/usr/X11R +6/include -I/opt/X11/include/freetype2 \-+- 05444 cmv /opt/homebrew/Cellar/perl/5.36.0/bin/perl +-I../t -MTkTest -e checked_test_harness('../xt', 0, '../blib/lib', '. +./blib/arch') t/basic.t t/crash.t \--- 05446 cmv /opt/homebrew/Cellar/perl/5.36.0/bin/per +l -w t/basic.t

      Running the following command from the CPAN build directory (/Users/cmv/.cpan/build/Tk-804.036-0) causes the hang:

      /bin/sh -c cd PNG && make test_dynamic LIBPERL_A="libperl.a" LINKTYPE= +"dynamic" OPTIMIZE="-O3" PREFIX="/opt/homebrew/opt/perl" PASTHRU_DEFI +NE=' ' PASTHRU_INC='-I/usr/X11R6/include -I/opt/X11/include/freetype2 + '
      The file that it seems to be hanging on is:
      /Users/cmv/.cpan/build/Tk-804.036-0/PNG/t/basic.t
        I'm having the same problem. What was the resolution of this error?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11147245]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-16 18:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found