0

So I just recently installed Linux after using Windows for my whole life. I also just installed the C++ IDE named code::blocks using the following command in the terminal:

sudo apt-get install codeblocks

Now whenever I try to run some source code I get this error

sh:1 /home/daniel/Desktop/Hey: Permission Denied

Any help/solution?

2
  • 2
    Did you save the source file with a .cpp extension? I have seen that error when someone saves without an extension.
    – muru
    Aug 5, 2014 at 9:04
  • 1
    Thanks.... really amazing community this is... sorry for my broken English (not my first language and I'm only 13) and yeah that fixed the problem!! Thanks very much
    – user312492
    Aug 5, 2014 at 9:18

1 Answer 1

3

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).

3
  • I would add that G++ is meant to work on Windows too, so it requires .cpp, or better .c++ extension for source files.
    – enedil
    Aug 14, 2014 at 23:25
  • 2
    @enedil I have never seen a file with a .c++ extension and I'd recommend against it: stackoverflow.com/questions/5171502/…
    – muru
    Aug 15, 2014 at 5:46
  • I won't find that document but I was reading a C++ style guideline which was recommending .c++.
    – enedil
    Aug 15, 2014 at 8:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .