-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to link together a Rust binary and a CMake C/C++ library? #575
Comments
I would also like to add I am facing a similar issue I believe. I receive similar errors from my cxx_build when I allow corrosion to dictate the rust linker. If I set NO_LINKER_OVERRIDE then everything builds but at runtime there are undefined symbols. |
corrosion provides the |
Thanks for your answer! There's something I don't understand then, I think.
corrosion_add_cxxbridge(iothub_client_cxx
CRATE MWE
FILES main.rs)
target_link_libraries(iothub_client_cxx iothub_client) but it didn't work, also because I then can't find the headers in the cxx-bridge include. Thanks! |
No, its supposed to work both ways. Here is a very simple example / test project which links a cpp library into a rust binary: https://github.com/corrosion-rs/corrosion/tree/master/test/cxxbridge/cxxbridge_cpp2rust |
Hi, thanks for your work. I am trying to use Corrosion to build a binary crate using a C/C++ CMake built library (the Azure IoTHub C SDK). What I don't understand (or perhaps I missed in the docs) is how should I link the two, as I currently can't do that using plain CMake, and I don't know if the problem is from Corrosion, CMake, cxx or rustc.
In practice, I noticed that linking using only CMake (doesn't matter if I use
target_link_libraries
orcorrosion_link_libraries
) will correctly set up the relevant-L
and-l
flags on the rustc command invocation, but apparently the libraries are not correctly read(?). At compile time I get errors like:Note that the function I'm calling (and for which I set up the interface using cxx) is plain C
IoTHub_Init()
in the librarylibiothub_client.a
, built by CMake in directoryMWE/build/out/iothub_client
. I checked and it is present, and the symbol is exported when usingnm
. You can see it is present in the rustc invocation (or at least it seems to me), but I get the error. Whereas, if I include them by thebuild.rs
script, the linking works, so I was wondering if the problem was on Corrosion side. What am I doing wrong? Thanks!Context:
CMakeLists.txt
build.rs
azure-iot-sdk-c
Cargo.toml
src/main.rs
The text was updated successfully, but these errors were encountered: