Calling a function in a shared library with its name and signature

I have a small DSL that should be able to load shared libraries and run the functions that they export. Finally, the problem is solved: dlopen, dlsym, LoadLibraryand GetProcAddress- all you need for cross-platform use of shared libraries. It is easy!

C ++ disagrees.

Thanks dlsym, etc., I have everything I need: a pointer to a function from the library, a signature representation from the source file, and ... it is impossible to call one with the other.

I just want to confirm that I think that no amount of cheating with varargs, variadic templates or other magic will help if all the type information I have is dynamic. I will go with one of the following solutions, and I will also like the opinions that are preferable (I tend to the latter).

  • Limit the signature to accepting and returning a pointer to the marshalled object and write a shell for each library with which the language will be used.

  • Compile DSL into a C-compatible language (read: C ++) so that the available information is available at compile time (read: second compile time).

+3
source share
1 answer

libffi . , , . Ffi , ABI, , , ..

++ name-mangling , , , ...

+3

All Articles