-
Been scratching my head for hours wondering what I'm doing wrong. I've used this successfully with other projects, but for some reason, I can't use it with this one without getting a bunch of errors:
The relevant code is: #[no_mangle]
pub extern "C" fn internal__Load__DynamicImage__FromMemory(
data: *mut u8,
len: usize,
) -> __DynamicImage__ {
let slice = unsafe { std::slice::from_raw_parts(data, len) };
let image = load_from_memory(slice).unwrap();
__DynamicImage__ {
image: Box::leak(Box::new(image)) as *mut image::DynamicImage as *mut c_void,
}
} Which is fed into cbindgen, resulting in the following __internal__imageload.hpp: struct __DynamicImage__ internal__Load__DynamicImage__FromMemory(uint8_t *data, uintptr_t len); Referenced by imageload.cpp: DynamicImage::DynamicImage(std::vector<char> data) {
this->img = internal__Load__DynamicImage__FromMemory((uint8_t*)data.data(),
data.size());
}; The function in question being what actually throws the linker error. I'm only using the library as I have in the past. And if you must compile, the cmake file handles the dependencies automatically, just make sure you have glm, GLEW, and libcurl. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I don't see anything there - perhaps you copied a wrong link?
Just to be sure: Is it in an If you run |
Beta Was this translation helpful? Give feedback.
-
It was that I had to make an What's happening now, though, is the linker prioritizes the main function from the Rust code over the one from my C code. Putting a main function within it causes that to be seen as
My CMakeLists.txt is here. What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
I don't see anything there - perhaps you copied a wrong link?
Just to be sure: Is it in an
extern "C" block
?If you run
nm -D yourRustLib.so
, does it showinternal__Load__DynamicImage__FromMemory
as T?And if you look at the actual failing linker command line, is
yourRustLib.so
a) on the line
b) to the right of your cpp image library?