Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the shared and static libraries of the Rust standard library?

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
like image 676
LightSith Avatar asked Nov 22 '18 18:11

LightSith


People also ask

What is a library in rust?

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.

What is the difference between shared library and static library?

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.

Can I import a go library into rust?

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.

When do we need to recompile a static library?

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.


2 Answers

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.

like image 139
LightSith Avatar answered Nov 02 '22 01:11

LightSith


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:

  • How to set the environmental variable LD_LIBRARY_PATH in linux
like image 35
Shepmaster Avatar answered Nov 01 '22 23:11

Shepmaster