rust_libloading icon indicating copy to clipboard operation
rust_libloading copied to clipboard

q: loading and extracting function from a static library

Open Sigurthorb opened this issue 11 months ago • 1 comments
trafficstars

I'm experimenting with loading and executing libraries dynamically in a rust binary and have had excellent results using this library. I wanted to also try to remove the dependency on glibc to support running in scratch containers and built a example .a static library.

When I try to load the static library it fails from dlopen with the following error:

Error: DlOpen { desc: "/path/to/my_static_library.a: invalid ELF header" }

I can 'solve' this by creating a wrapper crate with crate-type dylib

#[link(name = "my_static_library", kind = "static")]
extern "C" {
    pub fn run();
}

Is there a way I can load a static library at runtime without having to create a dynamic library shim?

Sigurthorb avatar Nov 27 '24 15:11 Sigurthorb

No, there is not, though notably this is not necessarily a fundamental limitation, but basically an extent of what is supported by the loader (also known as interpreter, dynamic linker, etc) binary has been loaded by or, in the case of Microsoft, the OS.

nagisa avatar Nov 27 '24 16:11 nagisa