dlsym() problem - Unix

This is a discussion on dlsym() problem - Unix ; why doesn't this program work on Linux? $ cat dltest.c #define _GNU_SOURCE #include #include int main(int argc, char *argv[]) { if (dlsym(RTLD_DEFAULT, "main")) printf("main found\n"); else printf("main not found\n"); } $ gcc dltest.c -ldl && ./a.out main not found On ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: dlsym() problem

  1. dlsym() problem

    why doesn't this program work on Linux?

    $ cat dltest.c
    #define _GNU_SOURCE
    #include
    #include

    int
    main(int argc, char *argv[])
    {
    if (dlsym(RTLD_DEFAULT, "main"))
    printf("main found\n");
    else
    printf("main not found\n");
    }

    $ gcc dltest.c -ldl && ./a.out
    main not found

    On Solaris, it works when using the Solaris linker, but fails when
    using the GNU linker.

    By "works", obviously I mean that the output is "main found".

    -frank

  2. Re: dlsym() problem

    On Dec 7, 5:55 pm, Frank Cusack wrote:
    > why doesn't this program work on Linux?
    >
    > $ cat dltest.c
    > #define _GNU_SOURCE
    > #include
    > #include
    >
    > int
    > main(int argc, char *argv[])
    > {
    > if (dlsym(RTLD_DEFAULT, "main"))
    > printf("main found\n");
    > else
    > printf("main not found\n");
    >
    > }
    >
    > $ gcc dltest.c -ldl && ./a.out
    > main not found
    >
    > On Solaris, it works when using the Solaris linker, but fails when
    > using the GNU linker.
    >
    > By "works", obviously I mean that the output is "main found".
    >
    > -frank


    Linking with -rdynamic makes it work for me.

  3. Re: dlsym() problem

    On Fri, 7 Dec 2007 18:42:36 -0800 (PST) fjblurt@yahoo.com wrote:
    > Linking with -rdynamic makes it work for me.


    me too. thanks.

+ Reply to Thread