【问题标题】:Linking issue CUDA 5.5 nsight链接问题 CUDA 5.5 nsight
【发布时间】:2013-11-13 07:23:07
【问题描述】:

我正在尝试使用 ubuntu 12.04 在 nsight 上编译 CUDA 5.5 应用程序

起初我遇到了一个关于缺少头文件的问题,例如#include <helper_cuda_drvapi.h>

为了解决这个问题,我将路径 /usr/include/samples/common/inc 添加到我的包含列表中。

这解决了缺少头文件的问题,但导致了一个新问题。

尝试在 nsight 上编译程序时出现以下错误

/usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:278:未定义对cuInit' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:279: undefined reference tocuDeviceGetCount'的引用 /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:290:未定义对cuDeviceGetName' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:291: undefined reference tocuDeviceComputeCapability'的引用 /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:294:未定义对cuDeviceGetAttribute' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:327: undefined reference tocuDeviceGetAttribute'的引用 /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:330:对cuDeviceGetAttribute' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:333: undefined reference tocuDeviceComputeCapability'的未定义引用 /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:336:未定义对“cuDeviceGetAttribute”的引用

有什么建议吗?

提前致谢

**********************更新************

基本上归结为我正在尝试在 linux 上编译“CUDA Video Decoder GL API”示例程序,但由于头文件存在一些错误,它无法正常工作。有谁知道这是为什么?

更新

【问题讨论】:

  • 尝试在helper_cuda_drvapi.h之前包含cuda.hcuda_runtime.h
  • 我看到他们是这样用 nvcc 修复它的,但我认为没有办法设置首先用 nsight 编译的内容
  • @RogerDahl 我相信您的评论是正确的。 OP 显然不明白,nsight EE 和 nvcc 的区别也不清楚。您能否将您的评论扩展为答案?我会赞成。
  • @RobertCrovella,在this answer 中,@talonmies 提到 nvcc 自动包含所需的标头。我猜helper_cuda_drvapi.h 是示例框架的一部分,仅用于.cu 文件,因此不包括 cuda.h 本身?

标签: cuda linker include header-files nsight


【解决方案1】:

未定义的引用指向 CUDA 驱动程序 API 方法。 helper_cuda_drvapi.h在顶部附近有以下评论:

用于 CUDA Driver API 错误处理的辅助函数(确保 CUDA_H 包含在您的项目中)

因此,在您的.cu.cpp 文件中,在#include <helper_cuda_drvapi.h> 之前,包括cuda.h

#include "cuda.h"
#include <helper_cuda_drvapi.h>

有关 CUDA 标头的更多信息,请参阅 this question

【讨论】:

  • 我已经这样做了,但是当我在 nsight 中编译程序时仍然遇到同样的错误
【解决方案2】:

需要手动链接libcuda(Nsight项目使用Runtime API)

要链接到这个库:

  1. 转到您项目的属性,打开常规 / 路径和符号
  2. Libraries 选项卡上添加 cuda(不带前缀或后缀 - 理论上应该使您的项目更加 clossplatform。您可能还想在添加库时选中“添加到所有配置” -否则它将适用于您当前的构建配置(例如“调试”或“发布”)。

更新:项目设置截图:

【讨论】:

  • 这个我也做过,我开始想最后是因为DirectX在windows上跑的,但是在Linux上不行,因为不支持DirectX
  • 我在 Linux 上测试过。可以肯定的是 - 我都按照 Roger 的建议添加了 #include &lt;cuda.h&gt; 并添加了 -lcuda 链接器标志。
  • 等你有“CUDA Video Decoder GL API”在linux上运行,如果是这样,请告诉我你用来使它工作的确切命令
  • 不,我只包含该标题,重现错误消息 - 然后修复了编译问题。
  • 你能从控制台视图粘贴整个 nvcc 调用吗?
猜你喜欢
  • 2020-12-29
  • 2012-07-10
  • 2011-03-29
  • 2011-09-03
  • 2013-12-15
  • 2014-05-17
  • 1970-01-01
  • 1970-01-01
  • 2016-12-17
相关资源
最近更新 更多