FSPB_main.cpp
int main(int args, char* argv[]){
.......
float *d_a;
cudaMalloc( (void**)&d_a, 5*sizeof(float) );
}
$ nvcc -L/usr/local/cuda/lib -lcutil -lcudpp -lcuda -lcudart -c -o
FSPB_main.o FSPB_main.cppFSPB_main.cpp: In function ‘int main(int, char**)’:
FSPB_main.cpp:167:45: error: ‘cudaMalloc’ was not declared in this
scope
What does this error mean? It’s just a cudaMalloc and it suppose to be supported for the compiler right?
Can functions like cudaMalloc be used in a .cpp file? Do I need to create a .cu file just for anything what comes from CUDA?
You need to include the header files where the CUDA functions are declared:
and then on the cmd line you also need to add the PATH (option
-I) where those includes are located.On my system, version 2.1 of CUDA installed the header files on
/usr/local/cuda. To compile, I would do something like:Don’t forget to add
-I.to that command if your code depend on custom headers you wrote that are located in the same directory of the source code.