dlsym returns NULL, even though the symbol exists
I don't think you can do that, dlsym
works on exported symbols. Because you're doing dlsym
on NULL
(current image), even though the symbols are present in the executable ELF image, they're not exported (since it's not a shared library).
Why not call it directly and let the linker take care of it? There's no point in using dlsym
to get symbols from the same image as your dlsym
call. If your testing
symbol was in a shared library that you either linked against or loaded using dlopen
then you would be able to retrieve it.
I believe there's also a way of exporting symbols when building executables (-Wl,--export-dynamic
as mentioned in a comment by Brandon) but I'm not sure why you'd want to do that.