I was wondering what was the correct way to set up a multi-file project. Basically I am having trouble at the linking stage.
In my main file I include the .cu files like you would a .h file, because that was the only way that seemed to work. I also tried putting function prototypes in a header file, but that didn’t work. So that works for functions, but for the global variables in other files, I get symbol redefinition errors. I have tried using macros to tell the compiler not to compile them if they have been defined before, but that didn’t work.
How am I supposed to do this?
My main file is a .c file, and the others are .cu files.
On Linux I use gcc/g++ to compile the .c and .cpp files respectively and nvcc to compile the .cu files. All the .o files are then linked using gcc. On Windows I have converted one of the examples int he SDK to be a “template” project for Microsoft Visual Studio C++ where there is a custom build rule for the .cu files. I don’t #include .cu files. You can define the host functions in the .cu files in a header file. You may need to declare them extern “C” if using C++ though sometimes I find that is not necessary either.
I think you are right. I switched my CC from gcc to g++ and my linking problems went away. I will try your full solution, but I think that it will prove be correct.