Alright... Now before you go and lynch me, I used the search and found numerous posts regarding this issue. Most of them ended with "C::B does not have anything to do with this." That might be the case, but I experience some different symptoms, or maybe everyone has the same ones.
The problem with the permission denied on build doesn't in fact seem to be on the rights of the file. I tested the case a bit, and after making first build and running, the process was gone from Process Explorer, there were no locks when tried with Unlocker, and the owner was as it was supposed to be, me.
Now I go to rebuild and get an instant "Permission Denied" error. I go check the file, and weirdly, the file doesn't have any owners anymore, at all. Unlocker finds still no locks. The file cannot be deleted. It's like a ghost. Wait a few minutes, and the file is gone, by itself. Then a rebuild -> everything works as it was supposed to.
Wondering WTH is going on, after running I delete the file through explorer. It is deleted instantly. Rebuilding on Code::Blocks, the build goes as it should, nothing wrong. Now that I'm on to something, I try something different: Clean-up on Code::Blocks - and voila, the ghost file is there, it has no owner, it's right's cannot be determined, it has no locks, it cannot be deleted. Building obviously fails. I can repeat this behaviour consistently.
So my suggestion here is that there is something wrong with the way Code::Blocks cleans up. If it uses MingW for cleaning up, the problem is obviously there. It seems as if the file is marked as deleted only in the file record, but not in the MFT, which would suggest this kind of behaviour (as in it takes a few minutes for the file system to catch up that hey, this file's been deleted!). (As a sidenote, I am definitely not an expert: these are just ideas and experiments)
Anybody have any idea how to fix it?