Encountering Problem When Compiling Jolt as Dynamic Library
Opened this issue · 0 comments
khandar-william commented
I'm trying to compile a Rust program that uses Jolt as a dynamic library (cdylib
).
But libloading
crate failed to load the compiled library (.so file).
thread 'main' panicked at src/main.rs:8:58:
called `Result::unwrap()` on an `Err` value: DlOpen { desc: "../lib-producer/target/release/liblib_producer.so: undefined symbol: _HEAP_PTR" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
To demonstrate the issue, I have provided the complete code in this repository .
There are 3 apps:
guest
is the sample fibonacci guest codelib-producer
is a Rust library package- dependency:
jolt-sdk
andguest
- target
[lib] crate-type = ["rlib", "cdylib"]
- in
src/lib.rs
it exports C functionsarbitrary_string
andexecute_guest_code
- it produces
lib-producer/target/release/liblib_producer.so
file
- dependency:
lib-consumer
is a Rust app that will load thelib-producer/target/release/liblib_producer.so
file and call the functions inside- dependency:
libloading
- dependency:
In lib-producer/src/lib.rs
, it exports function like this:
#[no_mangle]
#[allow(improper_ctypes_definitions)]
pub extern "C" fn arbitrary_string() -> String {
"Hello, World!".to_string()
}
Then in lib-consumer/src/main.rs
, it loads the dynamic library file and calls the function
unsafe {
// Load dynamic library
let lib = libloading::Library::new(LIBRARY_PATH).unwrap(); // Error happened here, before executing any function inside
// Execute arbitrary_string()
let arbitrary_string_fn: libloading::Symbol<unsafe extern "C" fn() -> String> = lib
.get(b"arbitrary_string")
.unwrap();
let arbitrary_string = arbitrary_string_fn();
println!("arbitrary_string: {:?}", arbitrary_string);
}
You can see the complete code here.
So, first I run cargo build -r
in lib-producer
.
Then I run cargo run
in lib-consumer
.
But I always got this error:
thread 'main' panicked at src/main.rs:8:58:
called `Result::unwrap()` on an `Err` value: DlOpen { desc: "../lib-producer/target/release/liblib_producer.so: undefined symbol: _HEAP_PTR" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Do you know what happened here?
Thank you.