I built a LLVM 13 toolchain with ‘CLANG_DEFAULT_LINKER=lld’ and it would appear that the resulting toolchain’s linker(ld.lld) ignores whatever is set in LD_LIBRARY_PATH. If I use -L in the clang++ invocation instead of setting LD_LIBRARY_PATH the linker finds my libs.
I am a but stumped, and I do believe I stumbled upon a wrong conclusion.
I built LLVM with gcc 7 on a Centos 7 machine.
Can you help me?
LD_LIBRARY_PATH exists to tell the run-time linker where to search for libraries, not the static linker. I believe GNU ld only uses LD_LIBRARY_PATH in very limited circumstances (when resolving DT_NEEDED for DSOs you’re linking against if they’re the native architecture).
The --rpath option can set the runtime search path. Some linkers (not ld.lld) also support a LD_RUN_PATH variable which is used as a default if --rpath is not given. If passing to clang use something like: -Wl,–rpath=libdir1:libdir2:libdir:…
(FWIW, I actually patched LD_RUN_PATH support for the version of lld I use, so that it works as a replacement linker for some tools that passes rpaths that way.)