How do you get C++ to compile from Code::BLocks? (Beginner to Linux)

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

1 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like