Skip to content
  • I get null for dli_sname:

    $ gcc test.c -ldl -o test
    $ ./test
    fname: ./test
    symbol: (null)

    How exactly are you building this?

  • Yes, that is correct; with your gcc invocation main isn't a dynamic symbol and consequently the dynamic linker won't be able to resolve it.

    To fix this you will need to explicitly tell the linker to export the symbols as dynamic using --export-dynamic or --dynamic-list. For instance,

    $ gcc -ldl -o test.o test.c -Wl,--export-dynamic
    $ ./test.o
    fname: ./test.o
    symbol: main
    Edited by Ben Gamari
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment