Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

q: loading and extracting function from a static library #164

Open
Sigurthorb opened this issue Nov 27, 2024 · 1 comment
Open

q: loading and extracting function from a static library #164

Sigurthorb opened this issue Nov 27, 2024 · 1 comment

Comments

@Sigurthorb
Copy link

Sigurthorb commented Nov 27, 2024

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?

@nagisa
Copy link
Owner

nagisa commented Nov 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants