I plan to write a new CUDA module for use in an existing code base. Because I don’t want to mess with my existig build system, I don’t want the my existing code to have an explicit CUDA dependency. Therefore I plan to build the CUDA modfules as a library and with C-linkage (as NVCC depends on an older version of GCC than my existing code base uses) as follows:
Following the tutorial Separate Compilation and Linking of CUDA C++ Device Code I’ve added the -dlink flag (I understand) in order to generate device code and the -lcuart flag in order to link using GCC (recall that I would like to link to the CUDA library to my existing code without introducing CUDA dependencies i.e. NVCC.
MWE.a: In function `__cudaUnregisterBinaryUtil':
link.stub:(.text+0xf): undefined reference to `__cudaUnregisterFatBinary'
MWE.a: In function `__cudaRegisterLinkedBinary_38_tmpxft_000019d4_00000000_7_MWE_cpp1_ii_d6d5cc43':
link.stub:(.text+0x5a): undefined reference to `__fatbinwrap_38_tmpxft_000019d4_00000000_7_MWE_cpp1_ii_d6d5cc43'
MWE.a: In function `__cudaRegisterLinkedBinary(__fatBinC_Wrapper_t const*, void (*)(void**), void*)':
link.stub:(.text+0x102): undefined reference to `__cudaRegisterFatBinary'
main.o: In function `main':
main.cpp:(.text+0x10): undefined reference to `runKernel'
collect2: error: ld returned 1 exit status
if i correctly understood you, you try to link together objfiles build by different, incompatible compilers. afaik, that’s impossible - executable should contain only one run-time library. the alternative is to build DLL file with one compiler and then call it from executable build by another compiler - each DLL file has its own run-time library. i’m a windows user, though, situation may be different on Linux
is the -ccbin g++ necessary? Usually nvcc picks the g++ version that it officially supports in the respective CUDA toolkit. By overriding this with -ccbin you’re making it use a possibly incompatible version (the system default compiler).
he said “NVCC depends on an older version of GCC than my existing code base uses” so it seems that his code is incompatible with nvcc-compatible version of gcc
My recommendation would still be to try this without the -ccbin g++
You’ll mix object code generated by different compiler versions. But there is a chance it will work, as the interface between both modules only uses plain C syntax.