How to specify sanitizer library location with -fsanitize?

I have a custom-built clang and libc++. I just tried to use address sanitizer and I get this error:

% /Dev/llvm-project/build_phase1/bin/clang++ [...] 
    -o my_program [...]
Error: ld: file not found: /Dev/llvm-project/build_phase1/lib/clang/17/lib/darwin/libclang_rt.asan_osx_dynamic.dylib

That dylib file is not present where it says it looked, under build_phase1. But it is present in the file I passed to -L, under build_sanitizers. Is there a way to tell it where to find the libclang_rt.asan_osx_dynamic.dylib file?

(I’m on macOS)

~ Rob

A flag would be nice, but to get past this I sym-linked the libclang_rt.asan_osx_dynamic.dylib file to the location it was expecting it, and now it appears to work.

You can set DYLD_LIBRARY_PATH=path/to/lib to directly tell it where to look at run time

Edit: how did you build compiler-rt?