2013-05-07 85 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?