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

I have some compiled library files that I need to use in a Remedy application, and the (minor) issue I'm having is getting DynaLoader to recognize the location of my libraries. At the moment, the only solution I have found is to:
use lib '/home/hdweb/lib'; BEGIN { push @DynaLoader::dl_library_path, '/home/hdweb/ars/api_701p1/lib' +; } use ARS; # ~/lib folder.
Which is just kinda ugly. I looked through DynaLoader's documentation and it doesn't seem to be listed anywhere. Is there a cleaner way of doing this?

Replies are listed 'Best First'.
Re: Cleanly adding a directory to DynaLoader's search path?
by chromatic (Archbishop) on Aug 22, 2007 at 05:16 UTC

    Sadly, that's the only way to do it.

Re: Cleanly adding a directory to DynaLoader's search path?
by Anonymous Monk on Aug 22, 2007 at 07:00 UTC
    ???
    =item @dl_library_path The standard/default list of directories in which dl_findfile() will search for libraries etc. Directories are searched in order: $dl_library_path[0], [1], ... etc @dl_library_path is initialised to hold the list of 'normal' directori +es (F</usr/lib>, etc) determined by B<Configure> (C<$Config{'libpth'}>). + This should ensure portability across a wide range of platforms. @dl_library_path should also be initialised with any other directories that can be determined from the environment at runtime (such as LD_LIBRARY_PATH for SunOS). After initialisation @dl_library_path can be manipulated by an application using push and unshift before calling dl_findfile(). Unshift can be used to add directories to the front of the search orde +r either to save search time or to override libraries with the same name in the 'normal' directories. The load function that dl_load_file() calls may require an absolute pathname. The dl_findfile() function and @dl_library_path can be used to search for and return the absolute pathname for the library/object that you wish to load.
      Well this is how I knew what array I needed to access in the BEGIN block. But it simply seems like an ugly solution. I noted the suggestion of a the $Config{'libpth'} setting, and as I understand it that is a setting from when perl is compiled.
      Now is it possible to alter the Makefile to specify the BSLOADLIBS library path? I wouldn't be against that to solve the problem, I simply lack the knowledge on how to implement it properly. I am assuming this is all that is lacking as from reading the Makefile, that line is empty.
      318 # --- MakeMaker const_loadlibs section: 319 320 # ARS might depend on some other libraries: 321 # See ExtUtils::Liblist for details 322 # 323 EXTRALIBS = -L/home/hdweb/ars/api_701p1/lib -licuucbmc -licu +i18nbmc 324 LDLOADLIBS = -L/home/hdweb/ars/api_701p1/lib -lpthread -licu +ucbmc -licui18nbmc 325 BSLOADLIBS = 326 LD_RUN_PATH = /home/hdweb/ars/api_701p1/lib
      I know this is the issue as ldd points to it:
      $ ldd ~/perl/i386-linux-thread-multi/auto/ARS/ARS.so linux-gate.so.1 => (0x00d37000) libpthread.so.0 => /lib/libpthread.so.0 (0x00110000) libicuucbmc.so.32 => not found libicui18nbmc.so.32 => not found libc.so.6 => /lib/libc.so.6 (0x00228000) /lib/ld-linux.so.2 (0x4bfe4000)
      After exporting LD_LIBRARY_PATH=/home/hdweb/ars/api_701p1/lib in bash, the two extra libraries are now properly found.