CUDA 6.0链接错误:未定义引用`__cudaUnregisterFatBinary'

 落幕YL他 发布于 2023-01-12 16:22

我想在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 
#include "cuda_test.h"

int main() {

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

  foo_wrapper();

  return 0;
}

有谁能够帮我?

1 个回答
  • 你需要链接到cudartcuda运行时.加-lcudart

    2023-01-12 16:24 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有