I tried to compile a axpy.cu file as specified in the official docs here:
clang++ axpy.cu -o exec --cuda-gpu-arch=sm_60 -L/usr/local/cuda -lcudart_static -ldl -lrt -pthread
But that gave a linker error and warning:
clang: warning: Unknown CUDA version. cuda.h: CUDA_VERSION=11060. Assuming the latest supported version 10.1 [-Wunknown-cuda-version]
/usr/bin/ld: cannot find -lcudart_static
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have clang version 11 installed. On running:
nvidia-smi
I read somewhere that I need to add a symbolic link to libcudart file or something if that helps.
I get the following output on running:
ld -lcudart_static --verbose
attempt to open /usr/local/lib/x86_64-linux-gnu/libcudart_static.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libcudart_static.a failed
attempt to open /lib/x86_64-linux-gnu/libcudart_static.so failed
attempt to open /lib/x86_64-linux-gnu/libcudart_static.a failed
attempt to open /usr/lib/x86_64-linux-gnu/libcudart_static.so failed
attempt to open /usr/lib/x86_64-linux-gnu/libcudart_static.a failed
attempt to open /usr/lib/x86_64-linux-gnu64/libcudart_static.so failed
attempt to open /usr/lib/x86_64-linux-gnu64/libcudart_static.a failed
attempt to open /usr/local/lib64/libcudart_static.so failed
attempt to open /usr/local/lib64/libcudart_static.a failed
attempt to open /lib64/libcudart_static.so failed
attempt to open /lib64/libcudart_static.a failed
attempt to open /usr/lib64/libcudart_static.so failed
attempt to open /usr/lib64/libcudart_static.a failed
attempt to open /usr/local/lib/libcudart_static.so failed
attempt to open /usr/local/lib/libcudart_static.a failed
attempt to open /lib/libcudart_static.so failed
attempt to open /lib/libcudart_static.a failed
attempt to open /usr/lib/libcudart_static.so failed
attempt to open /usr/lib/libcudart_static.a failed
attempt to open /usr/x86_64-linux-gnu/lib64/libcudart_static.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libcudart_static.a failed
attempt to open /usr/x86_64-linux-gnu/lib/libcudart_static.so failed
attempt to open /usr/x86_64-linux-gnu/lib/libcudart_static.a failed
ld: cannot find -lcudart_static
attempt to open /usr/local/lib/x86_64-linux-gnu/libcudart_static.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/cudart_static.a failed
attempt to open /lib/x86_64-linux-gnu/libcudart_static.so failed
attempt to open /lib/x86_64-linux-gnu/cudart_static.a failed
attempt to open /usr/lib/x86_64-linux-gnu/libcudart_static.so failed
attempt to open /usr/lib/x86_64-linux-gnu/cudart_static.a failed
attempt to open /usr/lib/x86_64-linux-gnu64/libcudart_static.so failed
attempt to open /usr/lib/x86_64-linux-gnu64/cudart_static.a failed
attempt to open /usr/local/lib64/libcudart_static.so failed
attempt to open /usr/local/lib64/cudart_static.a failed
attempt to open /lib64/libcudart_static.so failed
attempt to open /lib64/cudart_static.a failed
attempt to open /usr/lib64/libcudart_static.so failed
attempt to open /usr/lib64/cudart_static.a failed
attempt to open /usr/local/lib/libcudart_static.so failed
attempt to open /usr/local/lib/cudart_static.a failed
attempt to open /lib/libcudart_static.so failed
attempt to open /lib/cudart_static.a failed
attempt to open /usr/lib/libcudart_static.so failed
attempt to open /usr/lib/cudart_static.a failed
attempt to open /usr/x86_64-linux-gnu/lib64/libcudart_static.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/cudart_static.a failed
attempt to open /usr/x86_64-linux-gnu/lib/libcudart_static.so failed
attempt to open /usr/x86_64-linux-gnu/lib/cudart_static.a failed
Can someone help with this?
So I found a solution. Apparently the linker wasnt able to locate libcudart binary. So used find to get its location:
find /usr/ -name libcudart_static*
Got its path as:
/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudart_static.a
(might be different for you).
Just linked this path by using -L flag in the compilation command. New command:
clang++ axpy.cu -o exec --cuda-gpu-arch=sm_60 -L/usr/local/cuda -L/usr/local/cuda-11.6/targets/x86_64-linux/lib/ -lcudart_static -ldl -lrt -pthread