Tips for using Rust on NetBSD

Finding C libraries from pkgsrc (RPATH)

Many rust programs use C libraries. The pkgsrc versions are usually found and linked against, but in general, the RPATH is not set up correctly and running the binaries will fail with errors like

foo: Shared object "libintl.so.8" not found

You can set the rpath at build time using

# RUSTFLAGS="-C link-arg=-Wl,-R/usr/pkg/lib" cargo ...

but it's easier to let cargo(1) know about the default rpath you want to use by creating ~/.cargo/config.toml with the following contents:

[build]
rustflags = ["-C", "link-arg=-Wl,-R/usr/pkg/lib"]

or if you need X11 libraries, even better

[build]
rustflags = ["-C", "link-args=-Wl,-R/usr/pkg/lib,-R/usr/X11R7/lib"]