1

On another question (Can I have a dynamic library required only when used by the code?) I have noticed that it is possible to load functions from a shared library only when required to. But how does the name get found? On disassembled objects I can see that the function names such as _ZN5Foo3barEvso how does the program know how to find that? Also for overloaded functions they have slightly different names so how would you load 1 of those overloaded functions?

I have tried some basic research but I have not really found anything on this matter

TheDuck
  • 13
  • 5
  • 2
    You seem to be asking about [name mangling](https://stackoverflow.com/questions/1314743/what-is-name-mangling-and-how-does-it-work#:~:text=Name%20mangling%20solves%20the%20problem,with%20more%20than%20one%20meaning.). `_ZN5Foo3barEv` is a mangled symbol name, that accounts for overloading. – Drew Dormann Apr 01 '23 at 17:05
  • 1
    If this is Windows, the command line tool DUMPBIN /DEPENDENTS will reveal the exported functions and their respective names and ordinals. – R.J. Dunnill Apr 01 '23 at 17:07
  • Ah but how would you load a specific function that is name mangled if you only know what the programmer called the function? – TheDuck Apr 01 '23 at 17:13
  • 1
    @TheDuck from the documentation. Or if the program has provided it, a header files of names and function definitions. It's also much easier with a pure `C` interface. With a `C++` interface you also need to check for ABI compatability. – Richard Critten Apr 01 '23 at 17:49
  • Use pimpl. Define an abstract class. Extend it in dynamic library. Call a `get` wiht C linkage function from the dynamic library returning a pointer to the interface. You can also call a function returning a pointer to a tuple of functions. Who needs names? – Red.Wave Apr 01 '23 at 19:27
  • @RichardCritten ah so its much more complicated than just loading it. But what is ABI? – TheDuck Apr 01 '23 at 19:37

0 Answers0