Not Just ./a.out, but .dylib and .so Too — Separate Rust Builds
Setting prefer-dynamic = true in a Rust workspace enables dynamic-library linking for release builds. It is useful for optimizing build speed and binary size.
Workspace Cargo.toml
Workspace
[workspace]
# authors: KuuwangE <root@ql.gl>
# author repo https://github.com/shellcodesniper
resolver = "2"
members = [
"entry", # NOTE: Entry point
]
default-members = [
"entry",
]
[profile.dev]
prefer-dynamic = false # NOTE: Prefer dynamic linking
opt-level = 0
debug = true
[profile.release]
prefer-dynamic = true # NOTE: Prefer dynamic linking
opt-level = 3
debug = false
lto = true
# split-debuginfo = "unpacked"
Prevent "Could not found libstd-~~~.so"
ADD THIS to the binary module's Cargo.toml
[dependencies]
prefer-dynamic = "0"
[dev-dependencies]
prefer-dynamic = { version = "0", features = ["link-test"] }
But... If the Error Still Occurs,
Try this
MAC OS X
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD"
sudo ldconfig
./a.out
LINUX
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$PWD"
./a.out