Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: XSLoader/DynaLoader Can't Locate Library

by wbirkett (Acolyte)
on Jun 12, 2020 at 10:21 UTC ( [id://11117968]=note: print w/replies, xml ) Need Help??


in reply to Re^3: XSLoader/DynaLoader Can't Locate Library
in thread XSLoader/DynaLoader Can't Locate Library

While trying your suggestion, I may have stumbled on the cause of my problem. I modified the .pm file as you suggested, and ran my test file. The library paths were printed as you'd expect, but the library still did not load. I wanted to be sure the library was actually where I specified, so I cd'd to that folder and did a directory listing. Then I ran the test file again, and the library loaded!!

WBBirkett-M:perl5 wbirkett$ cd ~/ WBBirkett-M:~ wbirkett$ perl -I/Users/wbirkett/Library/Application\ Su +pport/TextMate/Pristine\ Copy/Bundles/PressCal.tmbundle/Support/lib/p +erl5 /Users/wbirkett/Desktop/Rmath_test.pl XXX=/usr/lib XXX=/usr/local/lib XXX=/Users/wbirkett/Library/Application Support/TextMate/Pristine Copy +/Bundles/PressCal.tmbundle/Support/lib/perl5 Can't load '/Users/wbirkett/Library/Application Support/TextMate/Prist +ine Copy/Bundles/PressCal.tmbundle/Support/lib/perl5/darwin-thread-mu +lti-2level/auto/ICC/Support/Rmath/Rmath.bundle' for module ICC::Suppo +rt::Rmath: dlopen(/Users/wbirkett/Library/Application Support/TextMat +e/Pristine Copy/Bundles/PressCal.tmbundle/Support/lib/perl5/darwin-th +read-multi-2level/auto/ICC/Support/Rmath/Rmath.bundle, 1): Library no +t loaded: libRmath.dylib Referenced from: /Users/wbirkett/Library/Application Support/TextMat +e/Pristine Copy/Bundles/PressCal.tmbundle/Support/lib/perl5/darwin-th +read-multi-2level/auto/ICC/Support/Rmath/Rmath.bundle Reason: image not found at /System/Library/Perl/5.18/darwin-thread-m +ulti-2level/DynaLoader.pm line 194. at /Users/wbirkett/Desktop/Rmath_test.pl line 1. Compilation failed in require at /Users/wbirkett/Desktop/Rmath_test.pl + line 1. BEGIN failed--compilation aborted at /Users/wbirkett/Desktop/Rmath_tes +t.pl line 1. WBBirkett-M:~ wbirkett$ cd /Users/wbirkett/Library/Application\ Suppor +t/TextMate/Pristine\ Copy/Bundles/PressCal.tmbundle/Support/lib/perl5 WBBirkett-M:perl5 wbirkett$ perl -I/Users/wbirkett/Library/Application +\ Support/TextMate/Pristine\ Copy/Bundles/PressCal.tmbundle/Support/l +ib/perl5 /Users/wbirkett/Desktop/Rmath_test.pl XXX=/usr/lib XXX=/usr/local/lib XXX=/Users/wbirkett/Library/Application Support/TextMate/Pristine Copy +/Bundles/PressCal.tmbundle/Support/lib/perl5 OK

So, the failure to load the library is somehow connected to the current directory in the Terminal app. I don't know why that would matter, but it looks this is a macOS problem, not a Perl problem.

Thank you again for your help.

Replies are listed 'Best First'.
Re^5: XSLoader/DynaLoader Can't Locate Library
by bliako (Monsignor) on Jun 12, 2020 at 11:37 UTC
    So, the failure to load the library is somehow connected to the current directory in the Terminal app. I don't know why that would matter, but it looks this is a macOS problem, not a Perl problem.

    If I understand right that by changing directory to that which *contains* the actual dylib file, it does work, then that could be because it possibly searches the current directory for the dylib file by default - perhaps not DynaLoader but the OS's dynamic library loader. So, that's to be expected I guess.

    Perhaps you can experiment with a directory without spaces, although that's far-fetched and in my linux box a dir with spaces works perfectly. Additionally run strace's OSX equivalent: dtruss as per perlfan's suggestion and/or export any shell debug variables like LD_DEBUG=yes and maybe OSX-specific DYLD_PRINT_LIBRARIES=YES and try to see what's going on. It could say that it did not find the library but it could mean that some other dependencies were not found. Don't forget there are 2 processes at play here: DynaLoader and OS's dynamic library loader.

      I found a solution to my problem, thanks to suggestions from you wise monks.

      macOS uses the environment variables 'DYLD_LIBRARY_PATH' and 'DYLD_FALLBACK_LIBRARY_PATH' for the location of dynamic libraries or 'dylibs'. From the Terminal app, I was able to load the Rmath dylib successfully by entering

      export DYLD_LIBRARY_PATH=/thepath

      before running my Perl scripts.

      Then I tried setting this variable in my Perl script, but this didn't work. Apparently, the variable must be set in the process that runs Perl. My software runs within TextMate, which uses Ruby to execute programs. So, I added a single line of Ruby code prior to executing Perl,

      ENV['DYLD_LIBRARY_PATH'] = "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/perl5"

      This did the trick. Now I'm back to productive work. Thanks again to all.

        It's great that you solved it but allow me to say that in my opinion it is not a robust solution if you will ever try to distribute this to other users or even if you install it on other systems, OSX or not. It only works if you called your module via that specific Ruby program. So that excludes the stand-alone use of your module. And provided that the installer of your module has placed the library in 'lib/perl5'. And because DYLD_LIBRARY_PATH is OSX specific. And because adding (in your case it is "setting" as you discard any previous content) DYLD_LIBRARY_PATH can interfere with other things including being able to call the perl interpreter itself. If you do it via terminal, it will affect all future commands on that same terminal only, if you do it via your shell init (.bashrc e.g.) will affect all commands you run under bash and if you do it in the Ruby script, it may affect all system commands run from within (I think?). For this the bash idiom DYLD_LIBRARY_PATH=/thepath command can be useful as it sets that env var for just running "command".

        I think the cleanest would be to do it via the XSLoader/DynaLoader by solving the problem at its root. But if it works as is, hey good job!

        bw, bliako

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11117968]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-19 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found