“/usr/bin/ld:找不到-lcudart”

“/usr/bin/ld:找不到-lcudart”

我是 Ubuntu 新手,使用 Ubuntu 14.04 64 位。我想要make一个使用的项目cudaopencv运行时出现以下错误cmake . && make

Linking CXX executable ground_estimation
/usr/bin/ld: cannot find -lcudart
collect2: error: ld returned 1 exit status
make[2]: *** [ground_estimation] Error 1
make[1]: *** [CMakeFiles/ground_estimation.dir/all] Error 2
make: *** [all] Error 2

这是输出ld -lcudart --verbose

attempt to open /usr/x86_64-linux-gnu/lib64/libcudart.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libcudart.a failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libcudart.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libcudart.a failed
attempt to open //usr/local/lib64/libcudart.so failed
attempt to open //usr/local/lib64/libcudart.a failed
attempt to open //lib/x86_64-linux-gnu/libcudart.so failed
attempt to open //lib/x86_64-linux-gnu/libcudart.a failed
attempt to open //lib64/libcudart.so failed
attempt to open //lib64/libcudart.a failed
attempt to open //usr/lib/x86_64-linux-gnu/libcudart.so failed
attempt to open //usr/lib/x86_64-linux-gnu/libcudart.a failed
attempt to open //usr/lib64/libcudart.so failed
attempt to open //usr/lib64/libcudart.a failed
attempt to open //usr/local/lib/libcudart.so failed
attempt to open //usr/local/lib/libcudart.a failed
attempt to open //lib/libcudart.so failed
attempt to open //lib/libcudart.a failed
attempt to open //usr/lib/libcudart.so failed
attempt to open //usr/lib/libcudart.a failed

libcudart存在于/usr/local/cuda/lib64并且我还添加到库路径中:

echo $LD_LIBRARY_PATH
/usr/lib/nvidia-current:/usr/local/cuda/lib64:/usr/local/cuda/lib:

这是输出ls /usr/local/cuda/lib64

libcublas_device.a   libcufftw.so.6.0.37    libnppi.so.6.0
libcublas.so         libcuinj64.so          libnppi.so.6.0.37
libcublas.so.6.0     libcuinj64.so.6.0      libnpps.so
libcublas.so.6.0.37  libcuinj64.so.6.0.37   libnpps.so.6.0
libcudadevrt.a       libcurand.so           libnpps.so.6.0.37
libcudart.so         libcurand.so.6.0       libnvblas.so
libcudart.so.6.0     libcurand.so.6.0.37    libnvblas.so.6.0
libcudart.so.6.0.37  libcusparse.so         libnvblas.so.6.0.37
libcudart_static.a   libcusparse.so.6.0     libnvToolsExt.so
libcufft.so          libcusparse.so.6.0.37  libnvToolsExt.so.1
libcufft.so.6.0      libnppc.so             libnvToolsExt.so.1.0.0
libcufft.so.6.0.37   libnppc.so.6.0         libOpenCL.so
libcufftw.so         libnppc.so.6.0.37      libOpenCL.so.1
libcufftw.so.6.0     libnppi.so

ld我应该在/usr/local/cuda/lib64路径中搜索以查找什么libcudart

答案1

建立一个指向正在搜索位置的libcuda符号链接。ld

sudo ln -s /usr/local/cuda/lib64/libcudart.so /usr/lib/libcudart.so

答案2

LD_LIBRARY_PATH用于ldconfig在执行时查找库时修改和相关工具的行为。

链接器工具ld不使用此变量。如果要使用位于非标准目录中的库,则必须使用-L命令的参数,如下所示:

ld -lcuda -L/usr/local/cuda/lib64

如果你已经下载了现有项目,但不知道如何在不破坏整个编译的情况下修改现有 Makefile,你可以运行制作以下方式:

export LDFLAGS=-L/usr/local/cuda/lib64
make

变量 LDFLAGS(也可以在 Makefile 中定义)用于ld在编译指令启动时向链接器 () 传递特定参数。

答案3

您可以创建链接而不是添加路径:

ln -s /usr/local/cuda/lib64/libcudart.so /usr/local/lib/
ln -s /usr/local/cuda/lib64/libcudart.a /usr/local/lib/

答案4

解决了

git clone https://github.com/inducer/pycuda.git
cd pycuda
sudo configure --cuda-root=/usr/lib/cuda-10.1

sudo ln -s /usr/lib/cuda-10.1/targets/x86_64-linux/include src/cpp/

或者将所有头文件从 /usr/lib/cuda-10.1/targets/x86_64-linux/include 复制到 /src/cpp/

我在 Pop-OS 19.10 上用过

相关内容