Combining Matlab and Cuda with mex-interface

I’m trying to port some C-code to Cuda. The C-code is called from matlab through the mex-interface. I’m having a hard time linking my files correctly. I have the cuda source code (where there actually isn’t any cuda specific code yet, just plain C) in a file called which also has a header file (geometry.h). This file contains two functions compute_face_geometry and compute_cell_geometry. I also have a file called mex_compute_geometry_cuda.c with the entry point for matlab (mexFunction).

I’m trying to make object files of the .cu file by compiling with nvcc and then make object files of the .c file and link using the mex function (inspired by the approach in this blog The problem is that when I try to run the final linking i get the following error

mex_compute_geometry_cuda.o: In function `mexFunction':

mex_compute_geometry_cuda.c:(.text+0x2f5): undefined reference to `compute_face_geometry'

mex_compute_geometry_cuda.c:(.text+0x355): undefined reference to `compute_cell_geometry'

Any suggestions on how to fix this problem? I’ve tried the same approach using gcc instead of nvcc (with a file without any cuda calls) and then it works just fine. Do I need to do something differently when using nvcc on the .cu file? All suggestions are apprecieated! (simple makefile attached)
mkfile.txt (766 Bytes)

You need to use extern C to avoid the C++ name-mangling performed by nvcc.

That did the trick! Thank you!