Easy question about splitting code

Hi everyone. This is quite a basic question but im struggling.

I have a .cpp file with a main function and i am calling a function that sets up GPU (allocates memory etc) - however this function is in its own file.


int main()



   return 0;


File: gpu.cu


void set_up_gpu()


     cudaMalloc()  // balh blah blah

     cudaMemcpy()  // blah blah blah

     callKernel()  // etc etc


HOWEVER, i have no idea how to deal with the header files to point to this function in main.cpp. What i have done is: i have a GPU.h that has a decleration for set_up_Gpu()

and the main has

#include “GPU.h”

BUT im getting errors! Its not executing. - ERROR LNK2005

If anyone could tell me how to structure the headers so that it compiles it would be great!!!

Thanks in advance.

It’s link error, it has nothing to do with header file (which you are handing fine, in a way you described it). Make sure that you compile both main.cpp and gpu.cu.

You must describe exactly what you’re doing. What platform/compiler/editor etc. What OS/distribution? Print/attach the exact main and GPU files(where is the #include that you say is there???) Are you using a command line or Microsoft Visual Studio? You must provide exact details.

You are right: it might be better to ask this question somewhere else.