Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

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


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

Thank you, bliako, for your suggestions. Unfortunately, strace is not available on my Mac. I wasn't able to coax any additional debug information. I also tried setting the $dl_debug flag.

I did modify the Rmath.pm file to use the DynaLoader module instead of XSLoader, sort of a reverse migration. The result was the same, even when pushing the exact .dylib folder path onto @DynaLoader::dl_library_path. When I add code to the .bs file, it is executed, so I used that to modify @DynaLoader::dl_library_path.

The default values for @DynaLoader::dl_library_path are '/usr/lib' and '/usr/local/lib'. The library loads correctly from either of those locations. I was able to load the library from other locations using the dl_load_file() function.

Replies are listed 'Best First'.
Re^3: XSLoader/DynaLoader Can't Locate Library
by bliako (Monsignor) on Jun 11, 2020 at 00:33 UTC
    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.

      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.

Re^3: XSLoader/DynaLoader Can't Locate Library
by perlfan (Vicar) on Jun 11, 2020 at 01:47 UTC
    >strace is not available on my Mac

    man dtruss

Re^3: XSLoader/DynaLoader Can't Locate Library
by karlgoethebier (Abbot) on Jun 11, 2020 at 05:44 UTC
    «...strace is not available on my Mac.»

    dtruss?

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

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

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

    No recent polls found