I’ve had this issue too.
One option is to try to try disabling optimisations.
I found it better to use the GCC compiler.
Neither solutions are ideal and it’s a shame this seems to happen out-of-the-box for non-trivial applications. Others may have better suggestions.