compile and link multiple cuda files

Here is the deal.

I compile RayBuffer.cu using…
[kost@lancia PovRay]$ nvcc -o obj/release/RayBuffer.cu_o -c RayBuffer.cu -I. -I/usr/local/cuda/include -I…/…/common/inc -DUNIX -O3

I then compile testbuffer.cu using…
[kost@lancia PovRay]$ nvcc -o obj/release/testbuffer.cu_o -c testbuffer.cu -I. -I/usr/local/cuda/include -I…/…/common/inc -DUNIX -O3

then i fail to link the two together to create an executable…
[kost@lancia PovRay]$ g++ -fPIC -o …/…/bin/linux/release/RayBuffer obj/release/RayBuffer.cu_o obj/release/testbuffer.cu_o -L/usr/local/cuda/lib -L…/…/lib -L…/…/common/lib -lcuda -lcudart -lGL -lGLU -lcutil
obj/release/testbuffer.cu_o(.text+0x531e): In function main': : undefined reference to CSphereBuffer::CSphereBuffer()’
obj/release/testbuffer.cu_o(.text+0x5345): In function main': : undefined reference to CBoxBuffer::CBoxBuffer()’
obj/release/testbuffer.cu_o(.text+0x536b): In function main': : undefined reference to CPlaneBuffer::CPlaneBuffer()’
collect2: ld returned 1 exit status

and if i comment out all the cuda code rename to *.C and do the following…

[kost@lancia PovRay]$ g++ -c testbuffer.C
[kost@lancia PovRay]$ g++ -c RayBuffer.C
[kost@lancia PovRay]$ g++ -o testbuffer RayBuffer.o testbuffer.o

it works. So there is something with linking two *.cu object that I don’t understand.
Everything works fine if I have the main() in RayBuffer.cu. I can intersect objects on the GPU. But when I move the main() to testbuffer.cu, compile the two *.cu files, then try to link and build an executable, for some reason it does not work. I even tried to create a shared library which has RayBuffer.cu in it. I then include that library in the last step above and I get the same results.
I also tried converting to c code using nvcc -cuda, then doing the same steps. i get the same results. I also tried externing. Same results.

Anyone have any ideas on how to successfully link to *.cu objects together? Or know what else I am doing wrong?

Thanks
Rob

undefined reference to `CSphereBuffer::CSphereBuffer()’ indicates that you have classes in your .cu file. nvcc is a C compiler by default. See the CUDA 1.1 release notes for instructions on enabling a c++ mode. But, be warned, the release notes call this an “alpha” feature.

You can also separate your c++ code into separate .C files, leaving behind only a few thin wrapper functions in the .cu files to call the kernels and setup textures. This is what I do.

One final note: if you are using textures or constant memory, the two .cu files will not be able to access the same texture even if you declare it extern. This is funny, but it is a limitation of the cubin compiling (cubins define textures and each .cu is compiled to a separate cubin). You need to #include .cu files together and only compile one .cu file in order for them to share textures.

Take a look here [url=“http://forums.nvidia.com/lofiversion/index.php?t31069.html”]http://forums.nvidia.com/lofiversion/index.php?t31069.html[/url]

I think this will solve your problem!