Search code examples
c++c-preprocessorpreprocessor-directive

How can I programmatically force the compiler to stop the compilation process after it encountered a user created error?


In my code I am using the #error preprocessor directive in order to create an error. However, it still continues the building process.

How can I force the building process programmatically to stop after encountering my error?

I am using Microsoft Visual Studio 2015, C++ v140, x86, for Windows 10.


Solution

  • From MSDN

    The #error directive emits a user-specified error message at compile time and then terminates the compilation.

    (Emphasis Added)

    If compilation is continuing after the #error directive, then you're doing something odd, or MSVC is broken.