linking .cu files and .c files

I’m trying to link up CUDA files with C files for a ray tracing project. Is the extern “C” function needed?

extern “C” is only on functions that need be called from files compiled by a c++ compiler, just like with any function compiled by a C compiler linked to a c++ project…

so, extern “C” isn’t really necessary?

well, I’ve been having a hard time trying to link up a .c file to a .cu file. The .cu file calls the c functions that come from different c files. I initially tried doing this without the extern “C” function, but they give me these “undefined reference to” message.

For a test, I have a main function in the matrix multiplier .cu file and a function that prints the results declared.

The function that prints results is defined in a .c file.

I tried this command line:
nvcc -c
gcc matrix_mult.o matrix_mult.c -L/opt/cuda/lib -lcudart

I had that “undefined reference to ‘(name of print function)’” without the extern “C”.

Is there a better way to link up this example?

Are you using CUDA 1.1? extern “C” may be necessary there since nvcc always mangles names now.

well I don’t really know what version it is since this is at some university server.

nvcc -version

ok. The version reads:

release 1.0, V0.2.1221