How to compile CUBLAS?

I’ve been writing CUDA code and it’s going well. I need to do some matrix-vector multiplication and I read that using the CUBLAS library might be the way to go, I’d like to compare my CUDA version with one using CUBLAS but I can’t get CUBLAS code to compile.

I’ve copied the C code example from the CUBLAS manual into a file with .cu extension and tried nvcc code.cu but all I get is undefined symbol error for every CUBLAS function in the code. I’m using a mac here, but have linux at work too. I’m guessing I need to set some link option but can’t seem to find any reference to that?

Cheers