When I compile my CUDA code with NVCC and I have already defined a preprocessing variable in the code, e.g. #define DEBUG_OUTPUT 0, is there a way to overwrite such a variable on the fly when compiling? I tried so specify the NVCC option -DDEBUG_OUTPUT=1 but this doesn’t work: It gives me:
warning C4005: ‘DEBUG_OUTPUT’: Macro-Redefinition
Whatever you specify after -D, it gets defined before processing the input files. However, it does not remove the definitions that occur in the file. So, if you write
-DDEBUG_OUTPUTbut then you have#define DEBUG_OUTPUTin the file, the latter is a redefinition of the former. To handle that case, you can write in the file:Note, it has actually nothing to do with nvcc. Same behaviour appears in C/C++.