Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "collect2: error: ld returned 1 exit status" mean?

I see the error collect2: error: ld returned 1 exit status very often. For example, I was executing the following snippet of code:

void main() {   char i;    printf("ENTER i");   scanf("%c",&i);    clrscr();    switch(i) {     default:       printf("\nHi..\n");       break;     case 1:       printf("\n\na");       break;     case 2:       printf("\nb\n");       break;     case 3:       printf("\nc");       break;   } } 

and I got this:

main.c:(.text+0x33): undefined reference to `clrscr'                        collect2: error: ld returned 1 exit status  

What does it mean?

like image 605
user3682120 Avatar asked Dec 03 '14 13:12

user3682120


People also ask

How do I fix ld returned 1 exit status?

The collect2: error: ld returned 1 exit status error message is easily fixed by removing an existing executable file inside your document. It is possible to remove the existing file that is running in the background by accessing the thread tools inside your system.


2 Answers

In your situation you got a reference to the missing symbols. But in some situations, ld will not provide error information.

If you want to expand the information provided by ld, just add the following parameters to your $(LDFLAGS)

-Wl,-V 
like image 20
fazineroso Avatar answered Oct 05 '22 18:10

fazineroso


The ld returned 1 exit status error is the consequence of previous errors. In your example there is an earlier error - undefined reference to 'clrscr' - and this is the real one. The exit status error just signals that the linking step in the build process encountered some errors. Normally exit status 0 means success, and exit status > 0 means errors.

When you build your program, multiple tools may be run as separate steps to create the final executable. In your case one of those tools is ld, which first reports the error it found (clrscr reference missing), and then it returns the exit status. Since the exit status is > 0, it means an error and is reported.

In many cases tools return as the exit status the number of errors they encountered. So if ld tool finds two errors, its exit status would be 2.

like image 92
Wojtek Surowka Avatar answered Oct 05 '22 18:10

Wojtek Surowka