5

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

pb2q
  • 58,613
  • 19
  • 146
  • 147
ndgibson
  • 119
  • 1
  • 2
  • 10
  • How are you building the SDK samples? Are there any compiler flags listed there that you aren't using with NVCC? – chrisaycock Sep 04 '12 at 17:18
  • I was building with "nvcc test.cu -o test", essentially. perreal's solution worked for me, though. – ndgibson Sep 05 '12 at 16:15
  • Spoke too soon, I compiled a different sample program that included cutil.h and I got the same error. – ndgibson Sep 05 '12 at 16:56

2 Answers2

6

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
perreal
  • 94,503
  • 21
  • 155
  • 181
  • 1
    This worked! I was able to compile this program from my home folder: http://www.resultsovercoffee.com/2011/01/our-first-cuda-c-program.html I got one warning that didn't seem to affect my success: "/usr/bin/ld: skipping incompatible /usr/local/cuda/lib/libcudart.so when searching for -lcudart" – ndgibson Sep 05 '12 at 16:17
  • I take that back, sorry. I spoke too soon, I compiled a different sample program that included cutil.h and I got the same error. nvcc -I/usr/local/cuda/include -L/usr/local/cuda/lib matrixmul.cu -o matrixmul matrixmul.cu:6: fatal error: cutil.h: No such file or directory compilation terminated – ndgibson Sep 05 '12 at 16:57
  • `cutil.h` is included in the SDK, so you also need to add `-I/CUDA_SDK_PATH/C/common/inc` to the nvcc options – perreal Sep 05 '12 at 16:58
  • That works for me. Thanks, and sorry again for not understanding the first time. – ndgibson Sep 05 '12 at 17:03
1

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.

pQB
  • 3,077
  • 3
  • 23
  • 49
  • This also worked, and it didn't throw the warning that I mentioned in perreal's answer. I'm new to stackoverflow - perhaps this is out of scope, but any reason why you don't like to use the CUDA SDK libs? I'm just getting started with CUDA so I'm keeping an eye out for tips. – ndgibson Sep 05 '12 at 16:19
  • Again, I spoke too soon. This is what I get when I build using this command line string: nvcc -I/CUDA_SDK_PATH/C/common/inc -L/CUDA_SDK_PATH/C/lib matrixmul.cu -o matrixmul matrixmul.cu:6: fatal error: cutil.h: No such file or directory compilation terminated. Sorry for the confusion. – ndgibson Sep 05 '12 at 16:58
  • Feel very foolish - I was leaving CUDA_SDK_PATH instead of substituting my own. It works now, thank you. – ndgibson Sep 05 '12 at 17:02
  • Regarding to the use of the SDK libs, I recommend search in stackoverflow. If you dont find an answer then you may ask a new question. – pQB Sep 06 '12 at 09:19