Updated DLL
Fixed DLL loading issues with Linux
This commit is contained in:
parent
5d17c3eeed
commit
5da0c7f397
6 changed files with 25 additions and 4 deletions
4
.cargo/config
Normal file
4
.cargo/config
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[target.x86_64-unknown-linux-gnu]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-Wl,-rpath,$ORIGIN",
|
||||||
|
]
|
|
@ -12,5 +12,9 @@ lto = true # Enables link to optimizations
|
||||||
opt-level = "z" # Optimize for binary size
|
opt-level = "z" # Optimize for binary size
|
||||||
strip = true # Remove debug symbols
|
strip = true # Remove debug symbols
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "harmony_link_client"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libloading = "0.8.0"
|
libloading = "0.8.0"
|
Binary file not shown.
BIN
Resources/libharmony_link_core.so
Normal file
BIN
Resources/libharmony_link_core.so
Normal file
Binary file not shown.
3
build.rs
3
build.rs
|
@ -29,4 +29,7 @@ fn main() {
|
||||||
fs::copy(&path, &dest_path).expect("copy failed");
|
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");
|
||||||
}
|
}
|
||||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -1,10 +1,20 @@
|
||||||
extern crate libloading;
|
extern crate libloading;
|
||||||
|
|
||||||
fn main() {
|
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,
|
Ok(lib) => lib,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error loading DLL: {}", err);
|
eprintln!("Error loading dynamic library: {}", err);
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -14,7 +24,7 @@ fn main() {
|
||||||
let func: libloading::Symbol<unsafe extern "C" fn()> = match lib.get(b"start") {
|
let func: libloading::Symbol<unsafe extern "C" fn()> = match lib.get(b"start") {
|
||||||
Ok(func) => func,
|
Ok(func) => func,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error finding function in DLL: {}", err);
|
eprintln!("Error finding function in dynamic library: {}", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue