How to call an executable that depends on a library already built but not installed yet?

Hello, people! I am recapturing my old, stalled work on TDE-on-NixOS. I have had some success compiling some libraries.

But now I am stuck with a novel probem:

An executable file is compiled and used in order to generate a file for the next phase(s).

But this executable needs to load a library, compiled previously.

If I try to run that binary file directly, it fails with the message:

./genembed: error while loading shared libraries: cannot open shared object file: No such file or directory

But when I execute directly LD_LIBRARY_PATH=../../tdefx ./genembed, it works without hassle.

My question is: how can I fix that problem in Nix? How can I call an executable tha needs of a librar not installed yet?

Here is a pastebin of the failed build log:

You could use patchelf to tell that binary where to find its library.
Be careful not to leak broken binaries from your build, though.

It is a bit harder. The binaries are generated in the middle of build phase. I would need to “inject” patchelfs after every single executable.

I found a better solution for now: export LD_LIBRARY_PATH pointing out these same directories containing the libraries. Fortunately it was easy.