gcc warning in CUBLAS [implicit declaration of function cudaMalloc]


I’m trying to use CUBLAS 4.1 in a program and I’m a bit confused about a warning in the compilation proccess. I’m using this simple code (in a file called cublaswarn.c):


int main()


    double** a;



    return 0;


As you can see, the program only allocates and deallocates memory.

If I compile with gcc 4.6.3 (from debian sid) as

gcc cublaswarn.c -o cublaswarn -lcublas

all runs OK

But if I compile with the options

gcc -std=c99 -Wnested-externs cublaswarn.c -o cublaswarn -lcublas

two warnings appears

cublaswarn.c: In function ‘main’:

cublaswarn.c:5:5: warning: implicit declaration of function ‘cudaMalloc’ [-Wimplicit-function-declaration]

cublaswarn.c:5:5: warning: nested extern declaration of ‘cudaMalloc’ [-Wnested-externs]

cublaswarn.c:6:5: warning: implicit declaration of function ‘cudaFree’ [-Wimplicit-function-declaration]

cublaswarn.c:6:5: warning: nested extern declaration of ‘cudaFree’ [-Wnested-externs]

I’ve searched in cublas_v2.h and in all the *.h files included the definitions of cudaMalloc() and cudaFree() but I didn’t find. I searched too the file cuda.h and I didn’t found the definitions.

The program runs, but I don’t understand where are the missing functions


You need to include cuda_runtime.h for all cuda routine like cudaMalloc, cudaFree…

Thank you very much. Now compiles without warnings.