0

I want to load a library in runtime using dlopen+dlsym calls. I want to list down the names of the functions which should be loaded using dlsym() and load these functions using a simple 'for' loop. Is there a way to mark functions(maybe using a 'gcc' attribute) to be loaded using 'dl' calls?

Thanks, Ram.

ram
  • 1
  • 2

1 Answers1

0

In Unix-like systems there is a command called nm which returns the symbols contained in a .so file. Usage is nm -g filename.so (you can find more here).

I guess you can call this command with an exec or something like that.

If you can't use exec, you will need to take part of the source code of the nm command and use it in your program

  • But nm will list all symbols in a given .so. I'm looking for only few functions. – ram Sep 28 '17 at 19:37
  • I guess you have to call `nm` and search the symbols that you want from the output in the C code. Alternatively, since you are executing commands, you can use the `grep` command to parse the output of `nm` in the same `exec` command. – Ararararagi Sep 28 '17 at 19:42
  • How can I find only the required functions in the grep output? – ram Sep 29 '17 at 03:04