When we are in a nix develop shell, how does it make the libraries available to the binaries?
I thought it set LD_LIBRARY_PATH env var, but echo $LD_LIBRARY_PATH gives /nix/store/qrrxach47c1bhxh97nibb9lyd2fg9j18-pipewire-0.3.48-jack/lib, which is not what I put in devShell = mkShell { buildInputs = [ <<here>> ]; };
LD_LIBRARY_PATH is a workaround for making foreign binaries run in a nix environment. When building a standard C application, LD_LIBRARY_PATH should not get modified.
When you compile a program using zlib, the Makefile (or autoconf, or meson, or cmake, or whatever) will use pkg-config to find zlib. nix build will set the environment variable PKG_CONFIG_PATH to directories containing pkg-config configuration files. That’s how zlib will be found.
Finally, at link time, the absolute path to the zlib .so file will be embedded in the linked binary so it gets found at run time.
If I compile a binary depending on zlib while inside nix develop and then exit nix develop , will the compiled library run fine?