3 ms·
> rust does not support dynamic linking of rust libraries. All rust applications are statically linked. That's not true. $ ldd /usr/bin/rustc linux-vdso.
by cesarb 2y ago
> rust does not support dynamic linking of rust libraries. All rust applications are statically linked.
That's not true.
$ ldd /usr/bin/rustc
linux-vdso.so.1 (0x00007fde30c44000)
librustc_driver-adb68da129cf8bba.so => /lib64/librustc_driver-adb68da129cf8bba.so (0x00007fde2cc00000)
libstd-aa46ce58aa106bb2.so => /lib64/libstd-aa46ce58aa106bb2.so (0x00007fde2cad3000)
libc.so.6 => /lib64/libc.so.6 (0x00007fde2c8e2000)
[...]
The Rust compiler itself (which is a Rust application) is dynamically linked to the Rust standard library and to a compiler driver library.
What Rust currently doesn't support (there's a desire to fix this someday), is dynamically linking with a Rust library compiled with a different version of the Rust compiler, unless the library has been restricted to a C-compatible ABI. That's because Rust currently does not have a stable ABI; things like structure layouts can change between versions of the compiler, and Rust makes heavy use of inlining.
- SkiFire13 2y ago> What Rust currently doesn't support (there's a desire to fix this someday), is dynamically linking with a Rust library compiled with a different version of the Rust compiler Note that even with the same compiler there a lot of factors that must remain the same to make the dynamic linking work properly. For example changing any compiler flag or dependency feature flag will likely result in incompatibility. The best way to guarantee that the dynamic library and the executable that loads it are compatible is to build everything as part of a single workspace (and yes, this means that if anything changes in the dynamic library crate then the executable that depend on it must also be rebuilt).