2011-05-14 34 views
2

我安裝了CUDA from an Ubuntu PPA。現在我想測試安裝。來自Ubuntu PPA的CUDA:編譯首個CUDA程序

我抓住了一個small sample program from another StackOverflow post。它導入cuda.h和cuda_runtime.h。這是否意味着我需要使用nvcc來編譯程序或者我應該使用gcc?

當我嘗試編譯時,我得到下面的錯誤。我如何告訴編譯器在哪裏可以找到必要的庫?另外,我如何自己找到這些庫?我不確定PPA安裝的位置,或者我應該查找的庫的名稱。

detect_cuda.c:(.text+0x2b): undefined reference to `cudaGetDeviceCount' 
detect_cuda.c:(.text+0x30): undefined reference to `cudaGetLastError' 
detect_cuda.c:(.text+0x47): undefined reference to `cudaGetErrorString' 
detect_cuda.c:(.text+0xba): undefined reference to `cudaGetDeviceProperties' 
+3

將'-lcudart'添加到鏈接器/編譯器 – Anycorn 2011-05-14 07:42:26

+0

是的,這樣做。謝謝! – 2011-05-14 07:57:06

+0

但爲什麼這是必要的?如果我在'lcudart'或'cudart'上搜索'nvcc -h',我什麼都找不到。它看起來像鏈接cuda運行時,但爲什麼這甚至是需要的? – solgar 2013-03-07 20:50:23

回答

2

將-lcudart添加爲評論中建議的Anycom。

nvcc -lcudart detect_cuda.cu