Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Setting library path in Makefile

by bangor (Monk)
on Apr 30, 2019 at 07:37 UTC ( #1233175=perlquestion: print w/replies, xml ) Need Help??

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

I have made my first XS module and need some help in creating the Makefile.PL. The module uses a library which is installed in '/usr/local/lib'. When I run my script I get an error:
Can't load '/usr/local/lib64/perl5/auto/Mail/SPF_Check.so' for module +Mail::SPF_Check: libspf2.so.2: cannot open shared object file: No suc +h file or directory at /usr/lib64/perl5/DynaLoader.pm line 190.
If I set the path using
export LD_LIBRARY_PATH='/usr/local/lib'
The script works. I'm sure there is a way of setting this path in the Makefile (using LIBS => [] ?) but I can't work out the correct syntax.

UPDATE - found the solution, see my comment below.

Replies are listed 'Best First'.
Re: Setting library path in Makefile
by Fletch (Chancellor) on Apr 30, 2019 at 12:58 UTC

    The exact syntax is going to depend on your compiler and/or linker, but you're going to want to have it shim in /usr/local/lib to the dynamic library search path it bakes into the .so file. What you want in libs is going to be along the lines of "-R/usr/local/lib -L/usr/local/lib -lspf2" or something close. If you're using gcc in place of ld you may need "-Wl,-R/usr/local/lib" instead.

    Alternately you could stick /usr/local/lib in your /etc/ld.so.conf but be aware that alters the shared library search path for everything on that system.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Setting library path in Makefile
by thanos1983 (Parson) on Apr 30, 2019 at 09:01 UTC

    Hello bangor,

    I am not expert on this area but based on my search I think this is what you are looking for ExtUtils::MakeMaker/PREFIX and LIB attribute.

    Let me know if this works for you.

    BR / Thanos

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Re: Setting library path in Makefile
by bangor (Monk) on May 03, 2019 at 06:42 UTC
    After a lot of fruitless searching and experiments I finally found the solution - can't believe how simple it is, and it was right here on this site.
    export LDFLAGS=/usr/local/lib perl Makefile.PL
    Like LD_LIBRARY_PATH the LDFLAGS is only temporary, but it is only needed while making the lib.

    Thanks for the help.

Re: Setting library path in Makefile
by Anonymous Monk on May 02, 2019 at 19:41 UTC

    Assuming Linux and glibc, you can either add /usr/local/lib to /etc/ld.so.conf (and run ldconfig) to add the directory to the usual runtime search path, or rebuild the library with -rpath=/usr/local/lib linker flag (if the linker is gcc itself, it should be -Wl,-rpath=/usr/local/lib instead).

    Unfortunately, this stuff is much more platform dependent than Perl itself.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2021-05-15 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?