The procedure I have followed in my post above has two issues:
The
ComplexTypes.cpp
filename must be turned toComplexTypes.cu
so thatnvcc
could intercept the CUDA keywords__device__
and__host__
. This has been pointed out by Talonmies in his comment. Actually, before posting, I was already changing the filename from.cpp
to.cu
, but the compiler was complaining and showing the same error. Therefore, I was ingenuously stepping back;In Visual Studio 2010, one has to use View -> Property Pages; Configuration Properties -> CUDA C/C++ -> Common -> Generate Relocatable Device Code -> Yes (-rdc=true). This is necessary for separate compilation. Indeed, at NVIDIA CUDA Compiler Driver NVCC, it is said that:
CUDA works by embedding device code into host objects. In whole program compilation, it embeds executable device code into the host object. In separate compilation, we embed relocatable device code into the host object, and run the device linker (nvlink) to link all the device code together. The output of nvlink is then linked together with all the host objects by the host linker to form the final executable. The generation of relocatable vs executable device code is controlled by the --relocatable-device-code={true,false} option, which can be shortened to –rdc={true,false}.