Thank you for your reply reckless, much appreciated.
No, installing CodeBlocks in the C:/Codeblocks directory didn't improve the situation. But, fortunately, I think I've finally managed to pinpoint the problem. It apparently has to do with the compiler's installation directory, in my case at least. Going to Settings -> Compiler and Debugger -> Toolchain Executables (Tab) , there's a section entitled "Compiler's Installation Directory".
Now, quite long ago, I had Dev-C++ installed on this machine, but have uninstalled it since, and was using MinGW and MSYS (and now CodeBlocks). However, the Compiler's Installation Directory for CodeBlocks was for some reason set to C:\Dev-Cpp , which was the installation directory for Dev-C++ when it was installed (and apparently did not get automatically deleted even after my uninstalling it). So, apparently, all this time CodeBlocks had been using the MinGW version found in the uninstalled Dev-C++ directory, which unsurprisingly was incomplete, and thus I was missing header files during compilation. No wonder it was behaving strangely!
So, I just set the Compiler's Installation Directory to a working version of MinGW, and the code now compiles without problems. Because my standalone MinGW version is slightly more recent than the one that came with CodeBlocks, I set the directory to the standalone MinGW's location, in my case C:/MinGW . However, I find that the problem is equally solved by setting it to the MinGW directory found in CodeBLocks own installation folder, and that's perhaps the preferred solution. In my case, it would be C:\Program Files\CodeBlocks\MinGW . Once this directory is set, the header files are located without problems.
Something interesting though is that CodeBlocks somehow "inherited" this erroneous setting, because this is the first time I notice it (and I certainly didn't set it myself). How can this occur? Could it have something to do with my system's PATH variable?
Another thing I notice but am not sure why it occurs is that CodeBlocks somehow "remembers" it's previous settings between successively uninstalling and reinstalling it (even though it's installation folder is automatically deleted with the uninstall process). That is, CodeBlocks remembers all my added include directories and linked libraries (and also remembered the erroneous Dev-C++ directory for the compiler) between successive reinstallations, without my having to manually reinput them upon reinstalling.
So, a question would be: Why does this happen, and from where does CodeBlocks reload those past settings after it has been reinstalled?
Anyway, I think that the reason why others have reported that source files compile if placed in the CodeBlocks installation directory but not outside of it probably shows that the issue is related with the Compiler Installation Directory. So I'd propose that anyone having similar problems check that this setting actually points to their compiler's directory.
Regarding GCC's support of Windows long names:
I'm not sure about this, although I've used GCC/G++ both through the MSYS command line and through an IDE, and it seems to handle long windows names fine and compile without problems. I have heard it said sometimes that it's a good idea to not include spaces in the install and project directories used, but I haven't come across any issues so far.
Okaya