http://qs321.pair.com?node_id=11112858

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

Hello

I am messing around with libraries on macOS, and I am having the following problems: when you install a new module, their dependences, for example dylib, get installed in standard locations. The module then call the dynlib from there. I want to use at RUNTIME other locations where I want to put such dylib.

Let's say I want to use Image::PNG::QRCode; which requires "libpng". Let's say I put the "libpng16.16.dylib" library in a custom directory on my Desktop and I delete any other copy of this library from its standard location. I tried to add the path like following

use lib '/Users/xx/Desktop/lib/libpng16.16.dylib'; #or use lib '/Users/xx/Desktop/lib';

I also tried to add the path to the env with in a begin block $ENV{'LD_LIBRARY_PATH'} = '/Users/xx/Desktop/lib'; with no success.

When I run my script, I get an error saying "Library not loaded: /usr/local/opt/libpng/lib/libpng16.16.dylib" which is the standard location (and I removed the dynlib!)

How can I force my script to look in another location for my libraries? I hope it makes sense.