CUDA链接错误

时间:2013-05-07 01:04:05

标签: cuda linker nvcc

这些命令是由Makefile以程序方式生成的,我基本上是从NVIDIA的教程页面复制的;它超过100行,如果您认为有必要,它会发布,但这些命令足以重现错误。

g++ -m64  -I/usr/local/cuda/include -I. -I.. -I../../common/inc -I/usr/local/cuda/lib64 -o shallowwater.o -c shallowwater.cpp

/usr/local/cuda/bin/nvcc -m64  -gencode arch=compute_10,code=sm_10 -gencode arch=compute_20,code=sm_20 -I/usr/local/cuda/include -I. -I.. -I../../common/inc -I/usr/local/cuda/lib64 -o shallowwatercudamain.o -c shallowwatercudamain.cu

g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -lcudart 

前两项工作;两个源文件都没有编译错误,但是当第三个命令运行时,我收到以下错误:

shallowwatercudamain.o: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00004e70_00000000-4_shallowwatercudamain.compute_20.cudafe1.cpp:(.text+0x36): undefined reference to `__cudaUnregisterFatBinary'
shallowwatercudamain.o: In function `__sti____cudaRegisterAll_66_tmpxft_00004e70_00000000_6_shallowwatercudamain_compute_20_cpp1_ii_runIt()':
tmpxft_00004e70_00000000-4_shallowwatercudamain.compute_20.cudafe1.cpp:(.text+0x46): undefined reference to `__cudaRegisterFatBinary'
collect2: ld returned 1 exit status
make: *** [shallowwater] Error 1

以下是一些相关的系统信息:

[foo@bar code]$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2012 NVIDIA Corporation
Built on Thu_Apr__5_00:24:31_PDT_2012
Cuda compilation tools, release 4.2, V0.2.1221
[foo@bar code]$ uname -a
Linux intel19 2.6.32-71.el6.x86_64 #1 SMP Wed Sep 1 01:33:01 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

我在这里发现了一个有类似错误的人:/usr/bin/ld: cannot find -lcudart 我很尴尬地说我发现了这个,除了g ++而不是gfortran之外做了同样的改变,并且它起作用了。之后,我再次尝试了它并没有奏效。我得到了同样的错误:

g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -L/usr/local/cuda/lib64

2 个答案:

答案 0 :(得分:3)

这个命令对我来说不合适:

g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -lcudart 

这个命令对我来说不合适:

g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -L/usr/local/cuda/lib64

这个命令对我来说是正确的:

g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L/usr/local/cuda/lib64 -lcudart

你需要告诉g ++在哪里寻找cudart库,这就是-L/usr/local/cuda/lib64开关的用途(所以它需要一个路径,你不能单独使用-L你需要告诉g ++要使用的库的名称,这就是-lcudart的用途。

答案 1 :(得分:1)

我意识到你没有把#34; -lcudart"在你的最后一行。在进行实际编译时,您是否链接到了cudart?