gcc/CUDA Linker Issue


I posted for some help the other day and I’m still stuck and was looking for some more advice. I’m further along but there’s something simple/subtle missing. I have a legacy project that builds a .so that get linked into a parent application. I use nvcc/Makefile to build my CUDA code to an object file and I have a my legacy Makefile to build my .so and I’ve included the cuda object file in that legacy Makefile. I can seen the cuda object file in the final link link so the link is happening however I get a link error that it cannot find the function in the cuda code object file and I get the following:
undefined reference to `__cudaRegisterLinkedBinar…

when I build the CUDA object I include the -dlink which I understand is required for follow-on linkage using gcc. using nm I can see the cuda function in the object code. Function prototypes are all there in both sets of code. Looks like all the pieces are there. Anyone have an idea what’s missing?
I’ve tested the cuda code with its own main to ensure it compiles,links and executes. works fine. Not sure what’s missing at this stage. Any help/advice?

-dlink is only required if you have cuda device code in once compilation unit calling or referencing cuda device code in another compilation unit. If you have built your CUDA code into a single object, (lets say because it started out in a single source file) then -dlink should not be necessary.

Furthermore, adding -dlink to the command line produces a special kind of object. The linking process when using dlink requires both an ordinary linked object and an object linked using -dlink. So if you are only doing -dlink, your link stage is broken.

You might want to refer to linking examples given in the nvcc manual. I gave you a link to the nvcc manual in your previous question.

I did read over the linking section of the manual. I cannot see that I’m doing anything wrong or missing anything.