Permission Denied error message while running C++ program in Code Blocks

I installed Code Blocks from Software Center. I wrote a C++ program and built it and it was fine, but whenever I try to run the compiled code it gives me this error: Permission denied. How can I fix this problem?


Solution 1:

You need the execute permission to run/execute the file. If the file is /home/user/test.cpp and you are the owner of the file then to execute the file you need the permission bits like:

-rwxr--r--  1 user user      1490 Feb 13 12:07 /home/user/test.cpp

Here only the owner ('user' in this example) can read, write and execute the file whereas the group ('user' in this case) and all others can only read the file.

To set the permission like this run the following command from Terminal:

sudo chmod 744 /home/user/test.cpp

If you do so, the execute bit will be set and you will now be able to execute the file.