Edit: Got sidetracked while composing this response. Seems you beat me to #error.
Using
static_assert could work. You can also use
#error.
Example:
#ifdef _WIN32
// Windows specific code
#elif __linux__
// Linux specific code
#else
#error OS not supported
#endif
As per the linked documentation, it doesn't matter if the string after #error is quoted or not.
To use static_assert, instead of #error, it might look something like this:
static_assert(false, "OS not supported");
Note: You can't simple use preprocessor #defines such as _WIN32, or __linux__ directly with static_assert, since if they're not defined (normally checked by #ifdef/#ifndef), there is no symbol substitution, so the compiler will see an unknown symbol. Also, to get this to compile under Linux, the newer version of C++ must be explicitly enabled: g++ -std=c++11 cppError.cpp