4

This is what I get when trying to compile a simple hello world program with gcc.

c:\>gcc hello.c
hello.c:9:2: warning: no newline at end of file
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot open output file a.exe
: Permission denied
collect2: ld returned 1 exit status

Does it have something to do with windows 7 administrative privileges?

If the output file is being created but cannot be opened, where is it located?

Sorry if this is too much of a noobie question. I have been using Dev-C++ for compiling my source code till now. I tried googling around the error but all i could find was the file is already open, but there is no mention of such exe in task manager.

Edit: Also the file is located at C:\hello.c

Will i be able to do it if i place it in other drive?

When i place the file at D:\ and try change it to any other drive using cd d:\ doesn't change the drive.

stirredo
  • 2,297
  • 3
  • 19
  • 23
  • 1
    To change to drive D use either `cd /d d:\ ` or just `d:`. But no, you don't want to work at the root of a drive. You can make yourself a directory with `mkdir` or use explorer if you have problems - explorer should help you work through permission errors with UAC prompts. – Rup Aug 10 '10 at 17:52

4 Answers4

6

Yes it is a permissions issue, you must not be running the command line window in Admin mode.

Don't work in C:\

Copy the file to a folder under my documents, or a subfolder of C:, or another drive.

Or, run the console in Administrator mode if you really want to work in the root of C:

To switch to D: while in C:, just type D: (you use CD only when already on the correct drive)

Fosco
  • 38,138
  • 7
  • 87
  • 101
1

The most common case is that your program may still be running in the background, possibly hanged on an endless loop. You can try searching for the process in the process list (press Alt+Ctrl+Del) and killing it.

Thomas Abraham
  • 356
  • 2
  • 9
alecov
  • 4,882
  • 2
  • 29
  • 55
  • I tried task manager, but there was no mention of the exe. I wrote that in description. Thanks for replying though. – stirredo Aug 10 '10 at 17:57
0

I found problem was hosting src under google drive;.. jesus super star chuck norris van damm .. 3h trying to figure out this one (vs code + mingw64).

Solution: Just moved the folder with my cpp source file outside google drive managed folder tree (was on f:\gd) so moved my source into f:\dev.

-2

The g++.exe-command in the build-log in the CodeBlocks-IDE shows the command with an additional path: C:\MinGW\lib, which is wrong.

  1. If you copy the command to a cmd-window (in the directory of your Project) without the C:\MinGW\lib the compiler works. When you copy the command as shown in CodeBlocks-Buil-log it fails, with the same message in the cmd-window.

  2. Have a look at the Settings > Compiler > Search Directories > Linker. You've got to delete the C:\MinGW\lib there, but the bug is, that it is not deleted if you do it once. You've got to repeat it and then it works.

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Hubert
  • 1
  • 1