I am a c++ beginner, working on a school project. We were given numerous working demo projects performing simple computations for us to understand the basics of CUDA.
Each of these projects has a structure like this:
main.cpp
#include <stdio.h>
// Prototype of function from .cu file
void run_cuda();
int main()
{
// Function calling
run_cuda();
return 0;
}
cuda.cu
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
void run_cuda()
{
... implementation ...
}
... other functions, kernel function ...
Now what I dont understand is - how can they call the run_cuda()
function from main.cpp when they never include any header file (and the header file is not even present in the project directory) or anything else that would tell the main.cpp file where to look for that function at?
At first I thought it might be an error, but every single project (even from multiple sources) has this structure. However when I try to do the same thing with my project, the compilation of main.cpp fails.
main.cpp: undefined reference to `run_cuda'