gcc

GCC #pragma to stop compilation


Is there a GCC pragma directive that will stop, halt, or abort the compilation process?

I am using GCC 4.1, but I would want the pragma to be available in GCC 3.x versions also.


Solution

  • You probably want #error:

    $ cd /tmp
    $ g++ -Wall -DGoOn -o stopthis stopthis.cpp
    $ ./stopthis
    
    Hello, world
    
    $ g++ -Wall -o stopthis stopthis.cpp
    
    stopthis.cpp:7:6: error: #error I had enough
    

    File stopthis.cpp

    #include <iostream>
    
    int main(void) {
      std::cout << "Hello, world\n";
      #ifndef GoOn
        #error I had enough
      #endif
      return 0;
    }