Clang link error for OpenMP target for NVPTX using LLVM@15.0.2 from spack

For the zaxpy example, clang++ can compile the code but the linker fails with error:

~/binutils-2.38-bqt3fzrygtetsydfdcbxzyotkf57jhrd/bin/ld: zaxpy.o: in function `zaxpy(std::complex<double>*, std::complex<double>*, std::complex<double>, unsigned long)':
zaxpy.cpp:(.text+0xbe): undefined reference to `__tgt_target_kernel'

~/binutils-2.38-bqt3fzrygtetsydfdcbxzyotkf57jhrd/bin/ld: zaxpy.o: in function `main':
zaxpy.cpp:(.text+0x4be): undefined reference to `__tgt_target_kernel'

~/llvm-15.0.2-uvnz4op3wy3tyvorvnrlknwdlrvqcjs3/bin/clang-linker-wrapper: error: 'ld' failed

Installation command:

spack install llvm@15.0.2 +cuda cuda_arch=86  targets=all build_type=Release 

The code works fine with gcc@12.2.0 and llvm@13.0.0 (both installed with spack). Can anyone help with a solution?

Thank you!

That’s usually because you have another (older) libomptarget installed somewhere at your system that is picked up. One way to workaround it is, to add -L path_to_the_right_openmp_lib_dir.

Thank you @shiltian for a quick response!

@jhuber6 @shiltian @JonChesterfield @ye-luo I thought we used rpath to prefer the install itself? Can we avoid these issues?

This is a separate issue. -rpath only influences the library chosen at runtime. What happens here is that it is using an older libomptarget for the linking phase, which doesn’t contain the needed function which was introduced in LLVM 15. You should be able to see the order the linker is looking at files via -Wl,--verbose or some other method to see the default library search order. The only way to solve this at the compiler’s level is to pass the path to the library directly rather than -lomptarget. But that would be an undesirable hack as well.