Description
I'm trying to set up a simple Rust library with a C++ interface, based on the demo
in this repo, using Cargo. I have quite a few questions, hope that's ok:
-
In
build.rs
it passessrc/demo.cc
to the code generator/compiler. If I'm only exposing Rust code to C++, and not the other way around, presumably I only need this if I have custom C++ bridging code, e.g. friendlier wrappers of the shared structs? -
If I remove these two lines:
.file("src/demo.cc") .flag_if_supported("-std=c++14")
then I get C++11 errors, in other words C++11 is always required. But doesn't that mean that the compiler should add -std=c++11
even if you don't explicitly pass that flag? Also what happens if you're using MSVC? I would have expected an API like .cpp_standard(CppStandard::cxx14)
.
-
I got a basic program working. After many link errors I figured out I have to link with the Rust dynamic library (
libdemo.dylib
) and with the cxxbridge static library (libcxxbridge-demo.a
) and thecxx
library (libcxxbridge04.a
). Can you explain what all those are? -
libcxxbridge-demo.a
andlibcxxbridge04.a
don't seem to get copied to a canonical location. In other words I have to link withtarget/debug/build/demo-78993d207bfe982b/out/libcxxbridge-demo.a
andtarget/debug/build/cxx-f3cb2e64024d3552/out/libcxxbridge04.a
. That doesn't seem right? I'd have expected them all to be copied or moved totarget/debug/
. -
If I have a function like this:
fn get_cpp_string() -> CxxString;
it saysreturning C++ string by value is not supported
. Is that a permanent thing? I'd really like the exposed C++ API to use standard C++ types rather thancxx
types because it is a public API rather than something internal. I can't see any reason why you couldn't return astd::string
by value.
Thanks!