Except that it isn't :)   Have you actually tried it?

Here's a simple example that mimics what's going on:

// foo.c // represents the XS lib referencing a symbol (lgamma) in an external +library libm.so #include <math.h> double foo() { return lgamma(42.0); } // mytest.c // this is just a wrapper which essentially does what perl/DynaLoader +is doing, // i.e. loading the XS lib (Foo.so) dynamically at runtime #include <stdio.h> #include <stdlib.h> #include <dlfcn.h> int main() { double (*foo)(void); char *error; printf("dynamically loading 'Foo.so'...\n"); void *so = dlopen("Foo.so", RTLD_LAZY); if (!so) { fprintf(stderr, "%s\n", dlerror()); exit(1); } dlerror(); *(void **) (&foo) = dlsym(so, "foo"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(1); } printf("%f\n", (*foo)()); dlclose(so); exit(0); }

Run the following commands

gcc -c -fPIC foo.c # compile gcc -shared -o Foo.so foo.o # create/link shared library F +oo.so gcc -rdynamic -o mytest mytest.c -ldl # create wrapper executable wh +ich loads Foo.so

Note that there are no errors while linking Foo.so, even though the command is missing the appropriate link instruction -lm referencing the math library!  As I pointed out, the shared library is created just fine.

Now, if you try to execute it you get the expected "undefined symbol" error at runtime:

$ LD_LIBRARY_PATH=. ./mytest dynamically loading 'Foo.so'... ./mytest: symbol lookup error: ./Foo.so: undefined symbol: lgamma

while if you link Foo.so with -lm (which corresponds to the step missing in the OP), everything works fine:

$ gcc -shared -o Foo.so foo.o -lm $ LD_LIBRARY_PATH=. ./mytest dynamically loading 'Foo.so'... 114.034212

In reply to Re^6: What's happened to Yaswi? by Eliya
in thread What's happened to Yaswi? by Steve_BZ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.