Preface:
In a C++ project, a source file contains a very large array, which contains unions, template function pointers ..., on Windows & Mac, the compilation time is 20 minutes, but on Linux, it's 2 minutes. So the problem is caused by compiler optimization.
Add some pragma, then the compilation time is much less than before.
#if defined (_WIN32)
#pragma optimize("",off)
#elif defined (__clang__)
#pragma clang optimize off
#endif
(remember to turn on optimization for the rest of code)
Reference:
#pragma optimize( "[optimization-list]", {on | off} )Mac:
#pragma clang optimize {on | off}
Gcc:
#pragma GCC optimize ("string"...)