How to undefine a define at commandline using gcc

Viewed 51362

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

}
6 Answers

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.

Related