When linked ,it just said “undefined reference to the function”.
However,if transform the .c file to a .cpp file ,everything is fine.
I am confused.
Thank you for any help.
It sounds like a name decoration problem.
c++ compiler would use C-style name decoration for file with extension .c .
when using nvcc, it would call third party C++ compiler (cl.exe or g++) to compile host code, I think that
compiler use C+±style name decoration.
If you want to call a function (say foo(void)) which is defined in a .cu file and you want to use C-style name decoration, then
you can declare “foo” in .cu file as
extern "C" {
void foo(void);
}
// definition of foo
void foo(void)
{
.....
}
Thanks for your help.
I have got it.