Have you been encountering the error ‘Collect2: Error: Ld Returned 1 Exit Status?’ Then you’ve come to the right place. In this article, we shall explore the nature of this error along with possible solutions. So read this article till the end.
What Does This Error Look Like?
Let us understand this error through an example:
when we try to run this 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; } }
In return we get this error:
main.c:(.text+0x33): undefined reference to `clrscr' collect2: error: ld returned 1 exit status
Why Does This Error Occur?
- This collect2: error: ld returned 1 exit status error message appears as a result of previous errors in your document, particularly when working in C++.
- It is one of the most common mistakes made by web developers, but it is also one of the simplest to correct.
- In other words, this error exists to indicate that the linking step in the creation process encountered issues.
- Because the exit status is greater than zero, this will result in an undefined reference.
- You can use multiple steps to create a search thread that will solve the problem.
- We will list and explain the various methods for correcting this error in your document.
How To Fix This Error?
- The ld returned 1 exit status error is a result of your previous errors, as there is an earlier error – undefined reference to ‘clrscr’ – in your example, and this is the real one.
- The exit status error simply indicates that some errors occurred during the linking step of the build process.
- Normally, exit status 0 indicates success and exit status > 0 indicates errors.
- Various tools may be running as separate steps to create the final executable while developing a program.
- In your case, one of those tools is ld, which reports the error it discovered (clrscr reference missing) before returning the exit status.
- Because the exit status is greater than zero, an error has occurred and has been reported.
- Include:
#include<stdlib.h>
- and use
System("cls")
instead ofclrscr()
Also read:- Error: Vector Memory Exhausted (Limit Reached?): 8 Steps To Fix – Full Guide
Conclusion
This exit status error message is easily resolved by deleting an existing executable file within your document.
Web developers are frequently plagued by the collect2 error in their syntax and are unable to debug it. Fortunately for you, you now have all of the information you need to remove this error from your document without affecting the rest of the syntax.
If you have any queries, please let us know in the comments below.