Ben McCann
Ben McCann

Reputation: 19014

CUDA from Ubuntu PPA: Compiling first CUDA program

I installed CUDA from an Ubuntu PPA. Now I want to test the installation.

I grabbed a small sample program from another StackOverflow post. It imports cuda.h and cuda_runtime.h. Does this mean I need to use nvcc to compile the program or should I use gcc?

When I try to compile I get the errors below. How do I tell the compiler where to find the necessary libraries? Also, how do I find those libraries myself? I'm not sure where the PPA installation put them or the names of the libraries I should be looking for.

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'

Upvotes: 2

Views: 3769

Answers (1)

Ben McCann
Ben McCann

Reputation: 19014

Adding -lcudart worked as Anycom suggested in the comments.

nvcc -lcudart detect_cuda.cu

Upvotes: 2

Related Questions