[c] 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?

This question is related to c compiler-errors

The answer is


Try running task manager to determine if your program is still running.

If it is running then stop it and run it again. the [Error] ld returned 1 exit status will not come back


Include: #include<stdlib.h>

and use System("cls") instead of clrscr()


clrscr is not standard C function. According to internet, it used to be a thing in old Borland C.
Is clrscr(); a function in C++?


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