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


13

我是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


可以ls /usr/local/cuda/lib64吗?
AlexGreg 2014年

我也遇到了同样的问题。文章的参考:[Debian使用IPP编译OpenCV示例:/ usr / bin / ld:找不到-llibsvml.so collect2:错误:ld返回1退出状态。] [1] [1]:stackoverflow.com/questions/ 24234961 /…
hellomzhxlp

Answers:


22

做一个符号连接到libcuda那里ld正在寻找它。

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

11

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

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

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

如果您已经下载了现有项目,并且在不中断整个编译的情况下不知道如何修改现有Makefile,则可以通过以下方式运行make

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

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


1
ld: warning: cannot find entry symbol _start; not setting start address跑步时得到了ld -lcuda -L/usr/local/cuda/lib64
Arash

@Arash:您是否安装了尝试编译的对象要求的libcuda版本?
Benoit 2014年

与@Arash相同的问题,是的,我有正确版本的libcuda
Mohsin Bukhari

2

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

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

我没有/ usr / local / lib64 /,我有/ usr / local / lib /
Arash


0

解决了

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上对我有用

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.