I’m trying to understand clang’s ordering of -L flags, which, on my system, leads to linking against a system libomp rather than the clang/LLVM libomp.
Specifically, on my system, running with -v shows that it specifies -L/usr/lib/x86_64-linux-gnu before the -L for my llvm/clang build/install directory. The effect is that it finds the system libomp.so.5 as libomp. When the executable loads, it then looks for libomp.so.5 instead of the libomp.so built for llvm, so even LD_LIBRARY_PATH doesn’t help it find the latter.
Is this intended behavior for some reason? Shouldn’t clang prefer its own libraries before system libraries?
A fix for my use case is to, in lib/Driver/ToolChains/Linux.cpp, move the following lines from near the end of the Linux constructor to earlier, right after the declaration of the Paths variable:
addPathIfExists(D, D.Dir + “/…/lib”, Paths);
By the way, in case it helps, the ToolChain constructor also tries to insert the following subdirectories of the build/install directory, but they don’t exist on my system: