dlsym() returns 0 for an existing function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sds57
    New Member
    • Jun 2010
    • 3

    dlsym() returns 0 for an existing function

    Sometimes I observe this in gdb:
    Code:
    (gdb) br my_function
    Breakpoint .. at 0x...: file ..., line ...
    i.e., "my_functio n" does exist in the current executable.
    however, dlsym does not find it:
    Code:
    (gdb) p dlsym(0,"my_function")
    $6 = 0
    This is a C program; dlsym does find other defined functions and variables.
    (this question stems from this bug report)

    What could cause this? How do I avoid this?
  • sds57
    New Member
    • Jun 2010
    • 3

    #2
    the presence of my_function is also obvious from
    Code:
    (gdb) p my_function
    $21 = {void (void)} 0x486f9c <my_function>

    Comment

    • sds57
      New Member
      • Jun 2010
      • 3

      #3
      it turned out that one has to link the executable with
      Code:
      ld -export-dynamic
      or
      Code:
      cc -Wl,-export-dynamic

      Comment

      Working...