-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Link C library with Rust project #2317
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I have discovered it appears when I return a pointer from a function.
int wasm_c_add(int a, int b) {
return a + b;
}
#[link(name = "wasm_c_add")]
extern {
pub fn wasm_c_add(a: c_int, b: c_int) -> c_int;
}
#[wasm_bindgen]
pub fn add() {
let sum = unsafe {
wasm_c_add(3, 6)
};
log::debug!("Addition = {}", sum);
} But if I wrote:
struct Something {
const char* value;
} Something;
struct Something* wasm_c_something() {
struct Something* something = malloc(sizeof(Something));
return something;
}
#[repr(C)]
pub struct Something {
pub value: *const c_char,
}
#[link(name = "wasm_c_add")]
extern {
pub fn wasm_c_something() -> *mut Something;
}
#[wasm_bindgen]
pub fn generate() {
let _something = unsafe {
wasm_c_something()
};
} it return the error:
I don't know if it can have a link with #190. But I have founded some support here |
That means that you're attempting to link to an undefined function. Upload your wasm file here, and look for functions at the top marked as |
Linking between C and wasm-bindgen Rust seems to still have several pitfalls discussed in #2209; could you be running into these? |
Describe the Bug
I have a part of the project in C, so I use emscripten to compile it (the complex Makefile is already present, that's why I don't want to use
cc
).With emscripten I generate a
lib.a
file.On a second time I have a Rust project to integrate the process.
For that I have defined the C API to call FFI from Rust and in the
build.rs
I add the link to thelib.a
.Using
wasm-pack build
everything is builded - not tested yet in web environnement.But in my case I need to target the Web Worker, so I try to compile with
wasm-pack build --no-module
which provides me that error:Does I missed something ?
Is it linked to a configuration on Emscripten side ?
Does I need to use Wasm in Wasm ? So generate a first wasm with Emscripten, then include bytes in the Rust code ?
Additional Context
Emscripten is used on Ubuntu (docker), Rust on Mac OSX.
The text was updated successfully, but these errors were encountered: