Friday, March 18, 2022

[SOLVED] Cannot open output file: Permission denied

Issue

so I'm completely new to Ubuntu. I've set up a shared folder with a few c programs and when I go to compile in Ubuntu, such as:

gcc file.c -o fileTest

I get the following error:

/usr/bin/ld: cannot open output file fileTest: Permission denied
collect2: error: ld returned 1 exit status

I'm sure that my permissions for the C files are correct, all files have 'rwx' permissions.

Do I have to change the permission of the fileTest as well?

I'm a complete newb, so apologies.


Solution

Try with sudo rm fileTest and re-run the command. This will work if the problem is that fileTest exists and you don't have permission to overwrite it.

It won't help if you don't have write permission for the directory. It will delete the file but the gcc command will still fail.



Answered By - Helio
Answer Checked By - Robin (WPSolving Admin)