c++ - CUDA 6.0 链接错误 : undefined reference to `__cudaUnregisterFatBinary'

标签 c++ eclipse cuda nvcc

我正在尝试在 Eclipse 中编译一个简单的 CUDA 程序。

g++ -L/opt/cuda/lib64 -o "cuda_esn" ./cu_cuda_test.o ./main.o -lcuda -lstdc++

如您所见,我正在链接 -lcuda 并设置库路径 -L/opt/cuda/lib64。但不幸的是,我不知道为什么这没有编译。

完整输出:

18:36:35 **** Incremental Build of configuration Default for project cuda_esn ****
make all 
Building file: ../cuda_test.cu
Invoking: CUDA NVCC Compiler
nvcc -c  -o "cu_cuda_test.o" "../cuda_test.cu" && \
echo -n 'cu_cuda_test.d' ./ > 'cu_cuda_test.d' && \
nvcc -M   "../cuda_test.cu" >> 'cu_cuda_test.d'
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
Finished building: ../cuda_test.cu

Building target: cuda_esn
Invoking: C++ Linker
g++ -L/opt/cuda/lib64 -o "cuda_esn"  ./cu_cuda_test.o ./main.o   -lcuda -lstdc++
./cu_cuda_test.o: In function `__cudaUnregisterBinaryUtil()':
makefile:32: recipe for target 'cuda_esn' failed
tmpxft_00001041_00000000-3_cuda_test.cudafe1.cpp:(.text+0x49): undefined reference to `__cudaUnregisterFatBinary'
./cu_cuda_test.o: In function `__nv_init_managed_rt_with_module(void**)':
tmpxft_00001041_00000000-3_cuda_test.cudafe1.cpp:(.text+0x63): undefined reference to `__cudaInitModule'
./cu_cuda_test.o: In function `__sti____cudaRegisterAll_44_tmpxft_00001041_00000000_6_cuda_test_cpp1_ii_aeee46d9()':
tmpxft_00001041_00000000-3_cuda_test.cudafe1.cpp:(.text+0x9c): undefined reference to `__cudaRegisterFatBinary'
collect2: error: ld returned 1 exit status
make: *** [cuda_esn] Error 1

这将是源代码(还不是很令人兴奋):

cuda_test.h

#ifndef CUDARR
#define CUDARR

#ifdef __cplusplus
  extern "C"
#endif

void foo_wrapper();

#endif

cuda_test.cu

#include "cuda_test.h"
#include "cuda.h"
#include "cuda_runtime.h"

extern "C" void foo_wrapper()
{
}

main.cpp

#include <iostream>
#include "cuda_test.h"

int main() {

  std::cout << "hello world" << std::endl;

  foo_wrapper();

  return 0;
}

谁能帮帮我?

最佳答案

您还需要链接到 cudart、cuda 运行时。添加-lcudart

关于c++ - CUDA 6.0 链接错误 : undefined reference to `__cudaUnregisterFatBinary' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23936170/

相关文章:

cuda - CUDA 的 __syncthreads() 和 blockIdx.x 的 OpenCL 模拟是什么?

c++ - 两个静态库

c++ - 我可以使用 istream_iterator<char> 将一些 istream 内容复制到 std::string 中吗?

eclipse - 使用 Eclipse 和 Tomcat 6 的 Servlet 出现 404 错误

java - 从函数构建端点值 - 注释属性 X 的值必须是常量表达式

java - jface 中最后一列变得过大

c++ - 到目前为止添加到 C++1y 的语言特性

c++ - 如何为静态类模板特化模拟构造函数?

c - 在 Tesla K80 集群中使用点对点获取 nan 结果

compilation - CUDA C 应用程序的分布式编译(类似于 distcc,但支持 nvcc 编译器)