Help with NVCC and cuBLAS problem

Hi,

I’m trying to compile a CUDA program that uses the cudaBLAS and the cBLAS libraries. No problem with the first one, but with second I always get an “undefined reference” error. I compile the program with this command:

nvcc  axpy.cu -o axpy -lcublas -lcblas

CBLAS library is correctly installed, cause I can compile with gcc (commenting the CUDA parts) without errors. The problem comes because NVCC calls the C++ compiler, and it’s g++ who returns the error. Here is the output to the above command with the --verbose option:

[...]

[...]

#$ gcc -c -x c++ "-I/usr/local/cuda/bin/../include" "-I/usr/local/cuda/bin/../include/cudart"   -I. -fpreprocessed -m32 -malign-double -o "/tmp/tmpxft_000015d0_00000000-12_axpy.o" "/tmp/tmpxft_000015d0_00000000-11_axpy.ii" 

#$ g++ -m32 -malign-double -o "axpy" -Wl,--start-group "/tmp/tmpxft_000015d0_00000000-12_axpy.o" -lcublas -lcblas   "-L/usr/local/cuda/bin/../lib" -lcudart -Wl,--end-group 

/tmp/tmpxft_000015d0_00000000-12_axpy.o: In function `main':

tmpxft_000015d0_00000000-1_axpy.cudafe1.cpp:(.text+0x4e8): undefined reference to `cblas_daxpy(int, double, double const*, int, double*, int)'

collect2: ld devolvió el estado de salida 1

# --error 0x1 --

I tried to compile with the option " --host-compilation C " but it doesn’t change anything. Any ideas?

I’ve never managed to get pure C already compiled (not C++) and nvcc to work without really weird tricks.

Is your library intended to be used with C++ ?

Perhaps give a try with :

extern “C” {

include <library_header.h">

}

I’m really interested in a “good” solution anyway :)

Thanks a lot, it worked!

At the beginning I was getting a different “undefined reference” message, cause I was not linking with the atlas library, but changing compiling line for

nvcc axpy.cu  -o axpy -lcblas -lcublas -L/usr/lib/atlas-sse3/

plus the tip you gave me worked great.

Weird thing is that in another system I don’t need to do anything of this, just link to cblas :mellow:

Well, thanks again!