0

I have installed MinGW on Windows 7 i did write a hello world app...

#include <stdio.h>
void main()
{
    printf("Hallo, Welt!\n");
};

i did run

gcc Hello.c -o Hello

this did create a exe app named Hello.exe I did run it and it said hello as it should

I did add a comment to the file, save it, and rerun the compiler in CMD as Admin then i got error

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot open output file Hello.exe: Permission denied
collect2.exe: error: ld returned 1 exit status

So i did try to delete the file in the windows file explorer a window did pop up and did ask me to use administrator rights to delete the file so i did permit this admin rights as i am admin then it did popup a other message ... i need some rights from the computer it self i dont know what i should do now ... i am admin of the computer and i cant delete the file ... if i rightclick the file and open the file settings and there the permissions i see the admin should have all permissions.

the file is not running as i see it ... the file is not locked by any thing

what is wrong ... is it because of the code or the compiler or is it a window thing ... how can i kill this file?

Edit: The file is not running ... in Taskmanager when displaying all tasks of any user the file dos not appear any how and is not running.

Antivirus is off and it has no influence on the problem i did also try with firewall off

the file keeps unkillable.

Mugolumbu
  • 31
  • 1
  • 6
  • Usually when you can't delete an EXE file it's because it's running. Check Task Manager? – user253751 Nov 13 '20 at 20:49
  • Something virus related, perhaps (quarantine?)...Reboot (to close all apps) and try deleting again... temporarlily disable anti-virus. – pmg Nov 13 '20 at 20:49
  • Your reboot idea may will work... but there must be a cause and a solution ... i do not want to reboot after any minor edit before i can compile.. the problem must have some solveable reason. may it is because it has no return value? but the main is void? maybe windows is doing something oder gcc? – Mugolumbu Nov 13 '20 at 20:58
  • Note that according to the C standard, `main` should have a return type of `int`. – Michael Nov 13 '20 at 21:19
  • @Michael note that according to C99, 5.1.2.2.3 (program termination), `void main` will return an unspecified termination status to the host environment, the program is otherwise valid –  Nov 13 '20 at 22:04

1 Answers1

0

I Found a solution... as it seems, until now...

I did delete C:\MinGW I did reinstall MinGW as as admin, in the install process i did check the option to install it for all users I did a check for the Windows Path variable in the System Settings, just to be sure it is still there for C:\MinGW\bin.

then i did try again to compile the file Hello.c and the error did appear again.

So i did create a new folder for the source C:\My_C_Files
Now i did right click it in the windows file explorer and whent to the folder properties to play around with the file/folder permissions. I gave wide rights to the user and all rights to the admin, namely such as allow to create subfolders read permissions delete write read change and just most to the user and the admin hat it all. I gave also ownership to the user and admin And all this rights i did apply to any subcontent of the folder even if it was empty. Then i did copy my *.c source code file into this new folder. I did try again to compile it from the CMD console, first once, as it did always work, then again, where the problem always did appear... this time it did work and overwrite the *.exe file again and again, to be sure i did delete the *.exe and recompile it and it did still work.

Conclusion: It has some thing to do with the Folder Permission of the Source or Destination Folder and the permission of its content and/or the Ownership of the desired folder.

now i have no longer ld.exe or collect2.exe - permission error's as returned 1 exit status with gcc.

May this info will help others who get into this error, i saw some on google, most say the app is running but this was not the case, others suggest to enable some windows services which did not help me, others talk about permission but mostly vague hints, some talk about symlinks and other crazy stuff. Here is what i found, windows permission to folder and content for user and admin.

Thanks to every one who did try to help me.

Mugolumbu
  • 31
  • 1
  • 6