-
Notifications
You must be signed in to change notification settings - Fork 339
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
Unsure how to use cxx #255
Comments
Looks like you are not running cxx's C++ code generator at all in your build script. Please check out https://github.com/dtolnay/cxx/tree/0.3.4#cargo-based-setup. |
In particular, the: Lines 230 to 233 in 85487b0
is specifically what generates and links your missing symbol. Your build.rs doesn't have anything like that. |
I'll close this for now, but please let me know if something still doesn't work after updating the build script! |
Sorry for the delay, I posted this just before leaving the office for a vacation. I think I'm closer to understanding as I managed to generate bindings. The only thing that is not clear right now is if it's possible to call my The bridge function signature currently is Thanks! |
This should not be any obstacle because you can insert as many extra Two possible approaches would be:
|
Thanks for your help, I understand now. |
Since cxx 1.0 there is a builtin way to obtain and manipulate use cxx::let_cxx_string;
#[cxx::bridge]
mod ffi {
unsafe extern "C" {
include!("foo/include_cpp/set.h");
fn setKey(key: &CxxString, value: &CxxString) -> i32;
}
}
fn main() {
let_cxx_string(key = "key...");
let_cxx_string(value = "value...");
let i = ffi::setKey(&key, &value);
println!("i={}", i);
} |
Hello! I am not sure what the steps are for creating a binding to a shared library in C++ (seems I am not alone in this #179 (comment)).
From my understanding, if I have the .so and its header:
I can create a new
foo-sys
lib crate which contains something like this in lib.rs:Then I write a build.rs that retrieves to .so that needs to be linked:
And the I add this
foo-sys
crate as my dependency and call the functions as:I get the following error, but I don't think it's that relevant because this seems more of a problem with me not being able to understand how to properly use the crate.
I fail to understand the example as I don't have any Rust code that I want to call from C++ and I don't really want to compile (I also don't think I can as I don't have sources) the library in
build.rs
. Can you please steer me in the right direction or tell me if got this completely backwards? Thanks!The text was updated successfully, but these errors were encountered: