Updated DLL

Fixed DLL loading issues with Linux
This commit is contained in:
Jordon Brooks 2023-06-04 00:41:26 +01:00
parent 5d17c3eeed
commit 5da0c7f397
6 changed files with 25 additions and 4 deletions

4
.cargo/config Normal file
View file

@ -0,0 +1,4 @@
[target.x86_64-unknown-linux-gnu]
rustflags = [
"-C", "link-arg=-Wl,-rpath,$ORIGIN",
]

View file

@ -12,5 +12,9 @@ lto = true # Enables link to optimizations
opt-level = "z" # Optimize for binary size
strip = true # Remove debug symbols
[[bin]]
name = "harmony_link_client"
path = "src/main.rs"
[dependencies]
libloading = "0.8.0"

Binary file not shown.

Binary file not shown.

View file

@ -29,4 +29,7 @@ fn main() {
fs::copy(&path, &dest_path).expect("copy failed");
}
}
println!("cargo:rustc-env=RUSTFLAGS=-C link-arg=-Wl,-rpath,$ORIGIN");
println!("cargo:rerun-if-changed=src/main.rs");
}

View file

@ -1,10 +1,20 @@
extern crate libloading;
fn main() {
let lib = unsafe { match libloading::Library::new("harmony_link_core.dll") {
// Use `cfg!` macro to detect OS
let lib_path = if cfg!(target_os = "windows") {
"harmony_link_core.dll"
} else if cfg!(target_os = "linux") {
"libharmony_link_core.so"
} else {
eprintln!("Unsupported OS");
return;
};
let lib = unsafe { match libloading::Library::new(lib_path) {
Ok(lib) => lib,
Err(err) => {
eprintln!("Error loading DLL: {}", err);
eprintln!("Error loading dynamic library: {}", err);
return;
},
}
@ -14,7 +24,7 @@ fn main() {
let func: libloading::Symbol<unsafe extern "C" fn()> = match lib.get(b"start") {
Ok(func) => func,
Err(err) => {
eprintln!("Error finding function in DLL: {}", err);
eprintln!("Error finding function in dynamic library: {}", err);
return;
}
};