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

Hello. Pls, do you know what kind of error is the following: "Can't load '..../CRFPP.so' for module CRFPP: libcrfpp.so.0: cannot open shared object file: No such file or directory at /usr/lib/perl5/5.8.8/i386-linux-thread-multi/DynaLoader.pm line 230" The file '..../CRFPP.so' exists. Thank you.

Replies are listed 'Best First'.
Re: cannot open shared object file
by almut (Canon) on Sep 26, 2007 at 13:35 UTC
    The file '..../CRFPP.so' exists.

    ... but apparently not the file libcrfpp.so.0, which CRFPP.so seems to depend on.  Without some more context, however, it's hard to tell what led to this problem, and how to solve it...

    Update: a bit more background: shared libraries can be linked against other shared libraries (which in turn may even be linked against further shared libraries...). In this case, they depend on them, i.e. they are not self-contained. If any one of the those libs is not found, the toplevel .so file cannot be loaded, which is why the message begins with "Can't load '..../CRFPP.so' ...". Sometimes (as in this case — but not always), you'll find more detailed reasons, if you carefully read on.

      I am sorry for being so 'rookie', but I just followed the instructions for making a perl binding for a c++ application (called crf++). Compilation was successful, except for some warning messages. The file 'libcrfpp.so.0' exists in /usr/local/lib (I added use lib "/usr/local/lib" to my script-don't know if this is correct) but the problem persists.
        I added use lib "/usr/local/lib" to my script

        This won't help here, as this only controls in which locations Perl will look for modules and their immediately related .so files. The secondary library dependencies have to be resolved/loaded by the system's dynamic linker (ld-linux.so on Linux), which has its own search path (LD_LIBRARY_PATH) and other facilities to control what to load from where and when (see "man ld.so" for details). In other words, as Sinistral suggested, one option would be to set/add /usr/local/lib to the LD_LIBRARY_PATH environment variable.

        A different option would be to link CRFPP.so statically against libcrfpp, but in this case you need the .a (archive) version of the library (which is probably available as well). See Re: Real Static Modules for how to achieve that when building the module yourself. In some cases this makes sense, in particular if you cater for easy deployment.

Re: cannot open shared object file
by Sinistral (Monsignor) on Sep 26, 2007 at 14:00 UTC

    The error indicates that the shared library file that the CRFPP modules depends on can't be found. I did some Googling, and discovered that the library you need for the CRFPP module is CRF++. The file CRFPP.so is a file that's part of the Perl CRFPP module. I did a CPAN search, but couldn't find the CRFPP module. Perhaps it's not available there?

    You need to make sure you have built the CFT++ code, or downloaded a binary package of it for your platform (which you didn't specify in your request for help; that would help considerably). If you have built the library, the next step is to tell your system where the libcrfpp.so.0 file lives.

    On Linux, if you have super user priveleges, you can edit the file /etc/ld.so.conf to add the path where you installed libcrfpp.so.0, then run ldconfig. After that, you can test if your module works by using this snippet on a command line

    /path/to/perl -e 'use CRFPP'

    If you get another command prompt with no errors, you're in business. If you still get errors, then something still isn't correct

    If you don't have root priveleges, you can still tell the run time linker program (ld) where you have put the lib using an environment variable

    • Linux, Solaris: LD_LIBRARY_PATH
    • AIX: LIBPATH
    • HP-UX: SHLIB_PATH

    If you are using a csh/tcsh type shell, you want to use set to set the variable, and if you're using a sh/bash/ksh type shell you want to use export.

    Whether you are using the environment variable or modifying /etc/ld.so.conf, you can use the code snippet to test whether your module is completely working. Remember, no messages == success, errors == failure

Re: cannot open shared object file
by gsiglet (Acolyte) on Sep 26, 2007 at 14:58 UTC
    I set LD_LIBRARY_PATH to '/usr/lib:/usr/local/lib' and now it works! Thank you! G.

      How did you do it? I tried $ENV{'LD_LIBRARY_PATH'}="/usr/local/lib:/usr/lib"; and I still get the same error

        you probably need to do "export LD_LIBRARY_PATH"