4 ms·
Calling C++ from "ffi" is very hard. With "C" there is almost one to one mapping of the function you wrote to what the compiler produced and linker sees (there
by malkia 12y ago
Calling C++ from "ffi" is very hard. With "C" there is almost one to one mapping of the function you wrote to what the compiler produced and linker sees (there could be an "_" or more added, or something similar, but that's it).
With C++ mangling (decorating) is specific per vendor, per compiler, and it might be even per compile options. Then you have different way of handling exceptions, new/delete, location of the this pointer, deep/shallow virtual tables, etc. etc. And for templates it's possibly very awkward to support them in any good way.
It could be that wrappers like SWIG might help there, but would require some amount of work, or rewrapping the C++ interface to be "C" like with "objects". Some API/library writers go to the extent where even if the library is written in C++, a "C" interface is provided, and a new "C++" interface is written on top of the "C" (e.g. it's not using the original C++ one). This might be due to problems with dynamic (RTTI) symbols and different linkage versions (since you've asked about MSVC - different runtime libraries loaded in your application - yes this is pretty normal for Windows).
- istvan__ 12y agoHaving great C++ support is good for using libraries from the C++ ecosystem, I guess. This might help Rust to get traction, but there might be other features with more interest from the community that gets prioritized.