4
votes

I've spent a lot of time setting up the CUDA toolchain on a machine running Ubuntu Linux (11.04). The rig has two NVIDIA Tesla GPUs, and I'm able to compile and run test programs from the NVIDIA GPU Computing SDK such as deviceQuery, deviceQueryDrv, and bandwidthTest.

My problems arise when I try to compile basic sample programs from books and online sources. I know you're supposed to compile with NVCC, but I get compile errors whenever I use it. Basically any sort of include statement involving CUDA libraries gives a missing file/library error. An example would be:

#include <cutil.h>

Do I need some sort of makefile to direct the compiler to these libraries or are there additional flags I need to set when compiling with NVCC?

I followed these guides:

http://hdfpga.blogspot.com/2011/05/install-cuda-40-on-ubuntu-1104.html http://developer.download.nvidia.com/compute/DevZone/docs/html/C/doc/CUDA_C_Getting_Started_Linux.pdf

2
How are you building the SDK samples? Are there any compiler flags listed there that you aren't using with NVCC? - chrisaycock
I was building with "nvcc test.cu -o test", essentially. perreal's solution worked for me, though. - ndgibson
Spoke too soon, I compiled a different sample program that included cutil.h and I got the same error. - ndgibson

2 Answers

5
votes

To fix the include problems add the cuda include directory to your compilation options (assuming it is /usr/local/cuda/include):

nvcc -I/usr/local/cuda/include -L/usr/local/cuda/lib test.cu -o test
1
votes

cutil is not part of the CUDA toolkit. It's part of the CUDA SDK. So, assuming you have followed the instructions and you have added the PATH and LIB directories to your environment variables you still need to point to the CUDA SDK includes and libraries directories.

In order to include that lib manually you must pass the paths to the compiler:

nvcc -I/CUDA_SDK_PATH/C/common/inc -L/CUDA_SDK_PATH/C/lib ...

Although I personally prefer not to use the CUDA SDK libraries, you probably will find easier start a project from a CUDA SDK example.