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

code-blocks

I install Code Blocks from Software Center . I write a C++ program and build it and it was fine. But whenever I try to run the compiled its give me this error: Permission denied . How can I fix this problem .

Best Answer

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.

Related Question