Due to some third party library, I have a situation where:
LD_PRELOAD=foo.bar cargo run --example yay
works, while
cargo run --example yay
fails.
=====
The nice thing to do would be to figure out wtf is going on in the third party library, write a patch, and submit a pull request.
I'm lazy. Is thee a way to hard code the LD_PREOAD into Cargo.toml ? Right now, when using IntelliJ, my examples/unit-tests are running without the LD_PRELOAD (and crashes), which forces mt to manually open up the "runtime env" of each example/env, tell IntelliJ to add the LD_PRELOAD, ... . I would prefer a way where I can just hard code this in Cargo.toml (or some other file) so that "cargo run" anywhere inside this crate always adds the LD_PRELOAD.
Solutions involving build.rs, this_crate/.cargo/* are acceptable too. [I can't get it to work adding println! to build.rs, and this_crate/.cargo/* seems to be getting ignored.]
A list of additional, user-specified, ELF shared objects to be loaded before all others. This feature can be used to selectively override functions in other shared objects.
(emphasis by me).
So, it might be an ordering problem, these are kinda hard to debug and find. The best way would be to create a core dump (if it really crashes with a SEGFAULT or similar) then then using a debugger to find out what exactly went wrong and where's the difference to without using it.
To make it static, you could use your ~/.bashrc and put the LD_PRELOAD content there. But be aware, that this applies to every binary you run.