2013-05-07 217 views
0

这些命令是通过Makefile生成的,我基本上是从NVIDIA的教程页面中复制的;它的长度超过100行,如果你认为它是必要的,它会发布它,但这些命令足以重现错误。CUDA链接错误

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 

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

[[email protected] 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 
[[email protected] 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 

回答

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的用途。

+0

这是做到了。谢谢!我想我试图复制它时只是读了修正错误。我正在修复我的Makefile来完成这项工作。 – 2013-05-07 01:24:00

1

我意识到你没有把“-lcudart”放在最后一行。当你进行实际编译时你有没有链接到cudart?