How to undefine a define at commandline using gcc

monkeyking picture monkeyking · Dec 30, 2009 · Viewed 42.6k times · Source

How do I at compile time undefine a compiler macro using gcc. I tried some compile args to gcc like -D but I can't get to see the "not defined" message.

Thanks

#include <iostream>

#define MYDEF


int main(){
#ifdef MYDEF
  std::cout<<"defined\n";
#else
  std::cout<<"not defined\n";
#endif

}

Answer

dcp picture dcp · Dec 30, 2009

You can use the -U option with gcc, but it won't undefine a macro defined in your source code. As far as I know, there's no way to do that.