Home Download Buy Blog Forum Support

collect2.exe: error: ld returned 1 exit status

collect2.exe: error: ld returned 1 exit status

Postby bluepimple on Tue May 06, 2014 10:06 am

#include <stdio.h>

int main(){
printf("Hello, World!\n");
return 0;
}

The above code, i build successfully in sublime Text.
[Finished in 1.9s]

#include <stdio.h>
#include <string.h>

int main()
{
char key[]="apple\n";
char input[80];
do{
printf("Guess my favorite fruit?");
fgets(input,80, stdin);
}while(strcmp(key,input)!=0);
puts("Good, Correct Answer");

return 0;
}
The above code i cannot compile, the error is below:
c:/mingw/64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot open output file C:\MyCode/Apple.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
[Finished in 1.5s]
When i compile cplus plus code, i also cannot compile, pls help.
bluepimple
 
Posts: 7
Joined: Tue May 06, 2014 10:01 am

Re: collect2.exe: error: ld returned 1 exit status

Postby mwb1100 on Tue May 06, 2014 8:11 pm

Is there some reason the linker wouldn't be able to create "C:\MyCode/Apple.exe"? Possibilities to consider might be:

- c:\MyCode doesn't exist
- permissions problems (as mentioned in the error)
- interference from antivirus programs
mwb1100
 
Posts: 37
Joined: Mon Jun 25, 2012 5:40 pm

collect2.exe: error: ld returned 1 exit status

Postby bluepimple on Wed May 07, 2014 3:27 am

Question:
Why HelloWorld in the same directory works?

- c:\MyCode doesn't exist -> Yes, it exist.
- permissions problems (as mentioned in the error) ->it works for Helloworld
- interference from antivirus programs ->

it works for Helloworld? i run the code in msys
g++ apple.c
./a
it works, but not in Sublime !!!

Tools>Build System>New System
How to overwrite default New System in Sublime
What is the command to run in
{
"shell_cmd": "make"
}
bluepimple
 
Posts: 7
Joined: Tue May 06, 2014 10:01 am

Re: collect2.exe: error: ld returned 1 exit status

Postby mwb1100 on Wed May 07, 2014 6:45 pm

The command `g++ apple.c` won't try to overwrite "apple.exe" since it creates "a.exe".

See if running "make" (which is what the Sublime project is configured to do) from the command line gives you the same error or not.

If it doesn't produce the same error, then you might need to use some other debugging tool like SysInternal's Process Monitor to get an idea of why the build process launched from Sublime doesn't have permission to overwrite "apple.exe".
mwb1100
 
Posts: 37
Joined: Mon Jun 25, 2012 5:40 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 21 guests