cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size); global void addKernel(int *c, const int *a, const int *b);
int AddVector();
When I try to compile, I got the following error message below.
1>main.obj : error LNK2019: unresolved external symbol _AddVector referenced in function _main
1>G:\MEHB1BPA_ME121104\FYP\SourceCode\Main\Debug\Main.exe : fatal error LNK1120: 1 unresolved externals
What is the setting that I missed out and I should check ?
Can anyone here give some shed of light ??
Only one I know is to use driver API. But this means You are not actally linking it together, like in a typical compilation. The host part is compiled with normal compiler, while any cu/cuh files are compiled with nvcc. The device code is compiled to PTX (mostly) in such a scenario and then loaded as modules to an app, very much like the GLSL shdares are loaded from a text file. This separates device and host code completely and is more portable, I think.
I dunno whether can it be done anyhow else. When I do programming in runtime API I always put all my code to cu/cuh files.
CUDA code in a .cu file compiled with nvcc is processed as C++ code, not C code. This means that all function names get decorated according to C++ rules, and therefore do not match the function names that the C compiler uses. That problem is common to any mix of C and C++ sources, so C++ has a mechanism that forces functions to conform to C naming convention. Such functions are declared as extern “C”. It’s easiest to apply that to the function prototype in the header file, then include the header file into both your .c file and your .cu file.
You will not be able to call a global function directly from C code. In your .cu file, create a wrapper function with extern “C” attribute that invokes the global function. You can then call the wrapper function from your c. file.