4 ms·
Thanks for your response! I would edit to clarify but missed the edit window on my post. > are you trying to call into C++ libraries from Rust/Swift using thei
by n8henrie 4y ago
Thanks for your response! I would edit to clarify but missed the edit window on my post.
> are you trying to call into C++ libraries from Rust/Swift using their FFI to C?
Yes. Examples (just POC, getting things to link and compile): <https://github.com/n8henrie/brokencppmap https://github.com/n8henrie/brokencppmap> <https://github.com/n8henrie/swiftcpp https://github.com/n8henrie/swiftcpp>
Thanks for the links -- I've been putting things together here and there from a combination of SO and the Rust user forum, which is why I was wondering about a more formal reference focused on this use case.
- rramadass 4y agoYou are on the right track; there is nothing difficult here but merely a bunch of moving parts to keep track of and understanding how they interact with each other. The SO articles i linked to earlier are very relevant and you should follow other links from their pages. That said there is one other crucial point to keep in mind when calling C++ from C. Using "extern C" for function declarations informs the C++ compiler to emit code to C ABI conventions so it can be called from C code. But what about data structures which you might pass and use between C++-land and C-land? They have to follow strict "POD" criteria for compatible memory layouts. See for example - https://stackoverflow.com/questions/49407290/memory-layout-differences-in-structs https://stackoverflow.com/questions/49407290/memory-layout-d...
- n8henrie 4y agoThanks again, I'll keep reading. For posterity, another good resource (at least for Swift): https://github.com/apple/swift/blob/main/docs/HowSwiftImportsCAPIs.md https://github.com/apple/swift/blob/main/docs/HowSwiftImport...