The normal behaviour of CodeBlocks when working on a single file (as opposed to a project) is to use the name of the file without any extension as the name of the compiled executable. So hello.cpp
will produce a binary named hello
. CodeBlocks checks the timestamps of the files to see whether compilation is needed. This breaks when the file doesn't have an extension: a source file named hello
would have a binary file named hello
from CodeBlocks' point-of-view. So timestamp checking fails, since it is comparing the file to itself. Hence CodeBlocks doesn't compile the code, and instead tries to run it directly, where it fails because the source file is not an executable. (This won't be a problem for executable source code like shell scripts.)
So always save C/C++ source code with an appropriate extension when using CodeBlocks (and in general, as well).
.cpp
extension? I have seen that error when someone saves without an extension.