Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by bliako (Monsignor)
on Jun 11, 2020 at 00:33 UTC ( [id://11117926]=note: print w/replies, xml ) Need Help??


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

When I add code to the .bs file, it is executed, so I used that to modify @DynaLoader::dl_library_path.

What about adding that code in the actual .pm file you created (Rmath.pm?) like:

package Rmath; ... our @ISA = qw( ... DynaLoader ... ); require DynaLoader; push @DynaLoader::dl_library_path, 'my-nonstandard-lib-path'; print "XXX=$_\n" for @DynaLoader::dl_library_path; bootstrap <Yourmodule> $VERSION;

$dl_debug : I meant doing export LD_DEBUG=all in your terminal/shell/prompt before testing your program (on that same terminal).

There are two very remote possibilities: 1) the dylib extension is not tried at all in enumerating possible library names (unlikely because it finds it in standard lib location), 2) the spaces in the library path (in OSX hmm that's not likely).

ps. the reason I suggested this reverse-migration is to investigate DynaLoader's behaviour without the front-man.

Replies are listed 'Best First'.
Re^4: XSLoader/DynaLoader Can't Locate Library
by wbirkett (Acolyte) on Jun 12, 2020 at 10:21 UTC

    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.

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-23 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found