开发者

Pass preprocessing variable to NVCC for compiling CUDA?

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:

w开发者_StackOverflow社区arning 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_OUTPUT but then you have #define DEBUG_OUTPUT in the file, the latter is a redefinition of the former. To handle that case, you can write in the file:

//if not specified earlier (e.g. by -D parameter)
#ifndef DEBUG_OUTPUT
//set it now to some default value
#define DEBUG_OUTPUT 0
#endif

Note, it has actually nothing to do with nvcc. Same behaviour appears in C/C++.


If a preprocessor macro is already defined and you are sure that you don't need whatever it was originally, just redefine it conditionally:

#ifdef MYMACRO
#  undef MYMACRO
#endif
#define MYMACRO my macro content
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜