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

I am trying to call a function from a C library from my Perl code on SCO Unix machine. I have been able to successfully call a stub function in a small library I created to link in with my Perl code. The problem occurs when I try access the real library from the stub code. I get a run time error that looks something like: "Dynamic Linker:Perl:Symbol not found:myfunctionname". I have been able to call functions from a different library written by others but I have not been able to find a difference between the implementations of the two libraries. I believe the problem may be related to the system not being able to find my library, but I'm not sure where the system is looking. Honestly, I believe the problem most likely lies outside my Perl code, but I was hoping someone with unix experience might give me an idea of what it takes to dynamically link with a C library from Perl on a unix machine. What I really need to know is: what do I need to do differently in my code, Makefile and environment, to allow me to link with a C library at run time and call a function from it. I think I have it 90% figured out but I'm missing something.....

Replies are listed 'Best First'.
Re: Accessing a C library from Perl
by Zaxo (Archbishop) on Sep 14, 2001 at 05:18 UTC

    Have you tried adding the lib location to $ENV{'LD_LIBRARY_PATH'} ?

    After Compline,
    Zaxo

(tye)Re: Accessing a C library from Perl
by tye (Sage) on Sep 14, 2001 at 19:44 UTC

    I hope SCO has added the "ldd" command since the last time I worked with it (many years ago). Use that command on the shared library that Perl creates to see what other dynamic libraries it expects to load and where it expects to find them.

    You can also check "man ld" and see if the environment variable LD_RUN_PATH is supported and have that set when you compile the module so that it contains a PATH-style list of directories to search for shared libraries when you run the module.

    You can also set LD_LIBRARY_PATH (everybody supports that, right?) when you use the module to the same thing.

    But I doubt it is actually a failure to find the shared library that is the problem. If it were, you should be getting a different error.

    Did you make the function "universal" so that it can be seen from outside the shared library? Can you link non-Perl programs to that shared library and successfully call that routine?

    You can also load shared libraries "by hand" inside the *.pm for your module. Or you can use FFI or C::Dynalib to access the shared library without building a module.

            - tye (but my friends call me "Tye")