CUDA 9.1: how to properly pass preprocessor definitions in visual studio ?

Hi,

I cannot make the property “Cuda C/C+±>Host->Preprocessor Definitions” work. Anything I type in there doesn’t end up on the command line. In addition “Cuda C/C+±>Host->Use Host Preprocessor Definitions” doesn’t seem to work either. My c++ files have a bunch of definitions, but my cuda command line ends up having no -D"…" for any *.cu files at all.
The only way I discovered working is to pass a bunch of -D flasgs into “Additional Parameters” field.

We had a similar problem for our OptiX-related project. Cross-referencing it here for convenience in case someone encounters a similar problem, perhaps it gets resolved (not resolved at the moment of posting):

https://devtalk.nvidia.com/default/topic/1064868/optix/host-pre-processor-definitions-are-not-passed-to-optix-cuda-kernels/

This is very weird. I have a little testing program I use for various things and I added this line to the CUDA module :

#ifdef _MBCS
#pragma message( "MBCS is defined in " __FILE__ )
#endif

The “Use Host Preprocessor Definitions” option was set to yes. The macro _MBCS is defined in the host code properties but not in the Host section of the properties. The weird thing is this message appears when compiling the CUDA code so it appears that option is at least partially working.

try to enter

--define-macro TEST_MACRO

in the “Additional options” field of the CommandLine property of the CUDA/C++ properties

this at least works for me for PTX files (on VS 2019 Community v16.2.3)