C++ 为什么在Ubuntu下编译CUDA示例时找不到libcudart.so.4?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10808958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:29:16  来源:igfitidea点击:

Why can't libcudart.so.4 be found when compiling the CUDA samples under Ubuntu?

c++unixubuntucudagpu-programming

提问by Alex

I'm trying to get my Cuda SDK samples running, but I get the following error:

我正在尝试运行 Cuda SDK 示例,但出现以下错误:

./bandwidthTest: error while loading shared libraries:
                 libcudart.so.4: cannot open shared object file:
                 No such file or directory

Why can I compile the example successfully, but not run it? Is there a way to specify the path to the CUDA runtime library manually?

为什么我可以成功编译示例,但不能运行它?有没有办法手动指定 CUDA 运行时库的路径?

回答by Edgar

try:

尝试:

32-bit: sudo ldconfig /usr/local/cuda/lib

32 位: sudo ldconfig /usr/local/cuda/lib

64-bit: sudo ldconfig /usr/local/cuda/lib64

64 位: sudo ldconfig /usr/local/cuda/lib64

cheers

干杯

回答by sj755

First these that you need is to concatenate the paths to the CUDA binaries and libraries. This is simply done by adding the following lines to your .bashrc file.

首先,您需要将路径连接到 CUDA 二进制文件和库。这只需将以下几行添加到您的 .bashrc 文件中即可完成。

export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=:/usr/local/cuda/lib64

If you are using a 32-bit operating system change lib64 to lib

如果您使用的是 32 位操作系统,请将 lib64 更改为 lib

Second, there should have been some shared object files installed in /usr/lib or /usr/lib64, depending on your operating system. These object files should be contained in a directory called "nvidia". The two files we are concerned with are names libcuda.so.drivernumber and libOpenCL.so.somenumber. To differentiate between the actual shared object files just use ls -l. The symbolic links will show what they are actually linking to.

其次,根据您的操作系统,应该在 /usr/lib 或 /usr/lib64 中安装了一些共享对象文件。这些目标文件应包含在名为“nvidia”的目录中。我们关心的两个文件是名称 libcuda.so.drivernumber 和 libOpenCL.so.somenumber。要区分实际的共享对象文件,只需使用ls -l. 符号链接将显示它们实际链接到的内容。

As root, execute the following commands:

以 root 身份执行以下命令:

ln -s /usr/lib64/nvidia/libcuda.so.somenumber /usr/lib64/libcuda.so
ln -s /usr/lib64/nvidia/libOpenCL.so.somenumber /usr/lib64/libOpenCL.so

That should allow you to compile all the sources in the SDK.

这应该允许您编译 SDK 中的所有源代码。

As of Cuda 5.5 and Ubuntu 12.04/12.10, the command above becomes (notice the Ubuntu and Cuda directory changes) for 64bit

从 Cuda 5.5 和 Ubuntu 12.04/12.10 开始,上面的命令变为(注意 Ubuntu 和 Cuda 目录更改)对于 64 位

ln -s /usr/local/cuda/lib64/libcuda.so.5.5 /usr/lib/libcuda.so.5.5

That is, the lib folders on Ubuntu as of 12.04 are lib32 and lib; the 64 is implicit, and cuda 5.5 and greater now installs to a different directory.

也就是说,从 12.04 开始,Ubuntu 上的 lib 文件夹是 lib32 和 lib;64 是隐式的,cuda 5.5 及更高版本现在安装到不同的目录。

回答by Jaime.Fernandez

1 error while loading shared libraries: libcudart.so.6.0: cannot open shared object file: No such file or directory

加载共享库时出现 1 个错误:libcudart.so.6.0:无法打开共享对象文件:没有这样的文件或目录

  32-bit: sudo ldconfig /usr/local/cuda/lib

  64-bit: sudo ldconfig /usr/local/cuda/lib64

(refer: http://blog.csdn.net/shenchong721/article/details/21529295)

(参考:http: //blog.csdn.net/shenhong721/article/details/21529295

Works for me!

为我工作!

回答by Jerome Berryhill

LD_LIBRARY_PATH is strongly deprecated. It may mess up other programs, and others may reset it. It should only be used to temporarily override the permanent paths for testing purposes (don't take my word, google it).

LD_LIBRARY_PATH 已被强烈弃用。它可能会弄乱其他程序,其他人可能会重置它。它应该只用于临时覆盖永久路径以进行测试(不要相信我的话,谷歌它)。

Instead, add a line with your cuda lib directory on it to /etc/ld.so.conf, after any existing lines.

相反,在任何现有行之后,在 /etc/ld.so.conf 中添加一行包含您的 cuda lib 目录的行。

For example, if you installed on /usr/local/cuda, you will need to add

例如,如果您安装在 /usr/local/cuda 上,则需要添加

32-bit : /usr/local/cuda/lib

32 位:/usr/local/cuda/lib

64-bit : /usr/local/cuda/lib64

64 位:/usr/local/cuda/lib64

Save, and run ldconfig. This should permanently fix the problem.

保存并运行 ldconfig。这应该可以永久解决问题。

The symbolic links are probably already set up by the installation. If not, then add them as Alex advised.

符号链接可能已由安装设置。如果没有,请按照亚历克斯的建议添加它们。

Note - I received errors referencing /lib, but I needed to add lib64 to fix them.

注意 - 我收到了引用 /lib 的错误,但我需要添加 lib64 来修复它们。

回答by surendran

create a nvidia_settings.conf file in /etc/ld.so.conf.d/ and add the path to the libs in the file nvidia_settings.conf

在 /etc/ld.so.conf.d/ 中创建一个 nvidia_settings.conf 文件,并在文件 nvidia_settings.conf 中添加 libs 的路径

 /usr/local/cuda/lib64
 /usr/local/cuda/lib

Now to update the changes run the following command:

现在要更新更改,请运行以下命令:

sudo ldconfig

回答by rodms

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib

or if you are running cuda-5.0 on a 64-bit machine

或者如果您在 64 位机器上运行 cuda-5.0

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-5.0/lib64

回答by dzhwinter

the system find library with ld tool. as the top answer says, 64-bit: sudo ldconfig /usr/local/cuda-xx/lib64 ;;xx is the cuda libraryedition

系统使用 ld 工具查找库。正如最佳答案所说,64 位: sudo ldconfig /usr/local/cuda-xx/lib64 ;;xx 是 cuda libraryedition

回答by user9869932

In my case I was running an application using MPI. The error was:

就我而言,我正在使用 MPI 运行一个应用程序。错误是:

libcudart.so.7: cannot open shared object file

CUDA was properly installed in all nodes. Also, as in the previous answers, the variables $PATH and $LD_LIBRARY_PATH were pointing to the binary and libraries respectively.

CUDA 已正确安装在所有节点中。此外,与之前的答案一样,变量 $PATH 和 $LD_LIBRARY_PATH 分别指向二进制文件和库。

Passing the $PATH and $LD_LIBRARY_PATH in the MPI command solved the issue.

在 MPI 命令中传递 $PATH 和 $LD_LIBRARY_PATH 解决了这个问题。

mpirun -x PATH=$PATH -x LD_LIBRARY_PATH=$LD_LIBRARY_PATH ...