I am trying to compile my Rust project with dynamic linking to reduce the size and provide .so (or .dll on Windows) files with the application just like Qt does for Android. I read Why are Rust executables so huge? and compiled with
cargo rustc -- -C prefer-dynamic
When I run my program, I get this error:
% target/debug/t_pro
target/debug/t_pro: error while loading shared libraries: libstd-a021829e87e39dcf.so: cannot open shared object file: No such file or directory
A collection of reusable, precompiled programs, scripts, or routines that can be called by the programmer while writing a code is called a Library in Rust. A Library in Rust helps the programmer to avoid extra work by not having to implement any logic or program again and again. A library in Rust is also called as crate.
A program using a shared library only makes reference to the code that it uses in the shared library. Static libraries are .a (or in Windows .lib) files. All the code relating to the library is in this file, and it is directly linked into the program at compile time.
In this article we explored building Go shared and static libraries that can be imported in Rust programs using foreign function interfaces. While not ideal, this could provide a very useful way of reusing a Go package in Rust. You can find the complete examples on GitHub.
For static libraries recompilation is required if any changes were applied to external files. On other hand for Shared libraries there is no need to recompile the executable. Static libraries take longer to execute, because loading into the memory happens every time while executing.
I got an answer on Reddit.
rustc --print=sysroot
In my case, the .so files are in /home/username/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib
and .rlib are in /home/username/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib
.
The libraries are installed wherever you chose to install Rust. I use rustup on macOS, so they are installed in ~/.rustup/toolchains/*whatever*/lib/
for me.
Use your operating system's tools to search for files of a specific name.
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With