The only way that's particularly effective is to offer your program as a web service of some kind, so that the compiled code is never even available on an end-user machine.
The next most effective solution, which is one that is widely used in practice, is to make your program so terrible that no-one wants to use it or spend the time reverse engineering it in the first place. I suspect that when this happens it is typically accidental, however.