Let’s say I have 3 files: test.c, test.h and test_kernels.cu. I’m also using Code::Blocks with all the nvcc setup requirements.
I have a function: void cuda_setup(int x) initialized in test.h, declared in test_kernels.cu and referenced in test.c . Everything compiles fine BEFORE I put in the reference into test.c but after I call the function I get an ‘undefined reference to cuda_setup’ error. test_kernels.cu IS being compiled into an object and if I plant an error in test_kernels.cu the compiler complains. However, if i copy/paste cuda_setup(int x) into test.c (or even a fourth file) everything compiles and links fine.
ARgh, this is frustrating. I can’t figure out what is wrong. I’m actually building on another person’s project and their code is split across 20+ .c files. I can put cuda_setup() into any other file and it works fine. It’s only ignored when it’s defined in test_kernels.cu. Any ideas why? Help would be saintly.
It’s compiling the .cu file into a .o, it complains when anything in the .cu file is wrong, and JUST now it even complained when I mismatched an ‘extern function()’ in the header with a ‘extern “C” function()’ in the actual declaration.
It just refuses to link the .cu object file with the rest of the same project. If i rename the .cu file to .c and remove the kernel everything works fine even without the ‘extern’. This must be a very very simple problem… that I apparently haven’t been able to figure out in days…
EDIT: I think i should have mentioned that the project I’m working off of is written in C and converting to C++ seems like it’ll be too much of a hassle. But, if there are no other alternatives…
Just a bump update: This isn’t a code::blocks error. I’ve got a seperate makefile and this problem still arises. The linker just refuses to see the functions within the .cu->object file.
Thanks for the help. This was part of the problem. The solution (in my case at least) was that the main() function HAS to be in my .cu file. Once I switched that, defined external function calls within an extern ‘C’ the problem was fixed.