链接到libcuda.so的问题 [英] Problems Linking to libcuda.so

查看:455
本文介绍了链接到libcuda.so的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被看似是一个应该很容易诊断和修复的问题困住了。我有一个使用CUDA驱动程序API的C ++源文件。当我使用 nvcc 进行编译时,可执行文件就会生成并且可以正常工作。但是,当我尝试使用 g ++ 编译它时,链接器抱怨未定义的<> /usr/lib/libcuda.so :



 未定义引用 cuDeviceGet'
。 ..未定义引用
cuDeviceComputeCapability'
...未定义引用 cuDeviceGetName'
...未定义引用
cuDeviceTotalMem_v2 '
...未定义引用 cuDeviceGetAttribute'
...未定义引用
cuDeviceGetAttribute'
...未定义引用 cuDeviceGetAttribute'
...未定义引用
cuDeviceGetAttribute'



我试图确保 / usr / lib 包含在库路径中(通过提供标记 -L / usr / lib -lcuda ,并将 / usr / lib 添加到 $ LIBRARY_PATH )。但是,问题仍然存在。我确信 /usr/lib/libcuda.so 包含链接器抱怨的符号:



  $ nm -D /usr/lib/libcuda.so | grep cuDeviceGet 
00000000000be410 T cuDeviceGet
00000000000bf120 T cuDeviceGetAttribute
00000000000d2e10 T cuDeviceGetByPCIBusId
00000000000be200 T cuDeviceGetCount
00000000000bdfa0 T cuDeviceGetName
00000000000d2bb0 T cuDeviceGetPCIBusId
00000000000bf380 T cuDeviceGetProperties


我发现奇怪的是 nvcc 成功地编译了这个文件,但是 g ++ 不。你有什么想法可以解决这个问题吗?



非常感谢您的帮助!

-lcuda 标志必须在之后 文件名。否则,它将无法工作......编译器告诉我这个信息的一个大的突出警告将会非常感谢。那么,这是浪费两个小时。


I am stumped by what seems to be a problem that should be easy to diagnose and fix. I have a C++ source file that makes use of the CUDA Driver API. When I compile it using nvcc, the executable is produced and works without problems. However, when I try to compile it using g++, the linker complains about undefined references to symbols that are in /usr/lib/libcuda.so:

undefined reference to cuDeviceGet'
... undefined reference tocuDeviceComputeCapability'
... undefined reference to cuDeviceGetName'
... undefined reference tocuDeviceTotalMem_v2'
... undefined reference to cuDeviceGetAttribute'
... undefined reference tocuDeviceGetAttribute'
... undefined reference to cuDeviceGetAttribute'
... undefined reference tocuDeviceGetAttribute'

I tried to ensure that /usr/lib is included in the library path (by supplying the flags -L/usr/lib, -lcuda, and adding /usr/lib to $LIBRARY_PATH). However, the problem still persists. I am sure that /usr/lib/libcuda.so contains the symbols that the linker is complaining about:

$ nm -D /usr/lib/libcuda.so | grep cuDeviceGet
00000000000be410 T cuDeviceGet
00000000000bf120 T cuDeviceGetAttribute
00000000000d2e10 T cuDeviceGetByPCIBusId
00000000000be200 T cuDeviceGetCount
00000000000bdfa0 T cuDeviceGetName
00000000000d2bb0 T cuDeviceGetPCIBusId
00000000000bf380 T cuDeviceGetProperties

I find it strange that nvcc successfully compiles the file, but g++ does not. Do you have any idea as to how I can fix this problem?

Thank you very much for your help!

解决方案

Ok, the reason I was not able to compile the file was because the -lcuda flag has to come after the filename. Otherwise, it won't work... a large, prominent warning with the compiler telling me this information would have been much appreciated. Well, that was a waste of two hours.

这篇关于链接到libcuda.so的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆