Skip to content

How to fix ‘Collect2.exe: error: ld returned 1 exit status’ error?

  • by
  • 2 min read

As easy as programming has become today, there are still small mistakes that beginner programmers make that can take hours to debug. Depending on the language you’re using, a missing reference or a skipped semicolon can cause quite the headache.

In this article, we’re talking about how to fix the “collect2.exe: error: ld returned 1 exit status” error and giving you three solutions for the problem. 

Also read: Python vs Java vs C/C++: Key differences and Pros-Cons


Check your imports

Before you go ahead and use a library in C/C++ or just about any programming language, you’re going to have to import the required modules or components to be able to reference said library. 

Try including stdlib.h and conio.h (if using TurboC) in your program to see if that solves your problem. Simply add the following lines at the top of your script.

#include <stdlib.h>
#include <conio.h>

Pay special attention to file names and extensions. Names are case sensitive and .h and .hpp extensions are not interchangeable. 

Also read: How to fix Dev C++ build error?


Close the previous console window

When you’re knee-deep in the debugging process, console windows can rack up easily. However, if you’ve got the console window from a previous execution or another program already running, it can conflict with any new programs you might try to run. Check to make sure all previous console windows are closed, save your code and try running it again. 


Close the program and rerun

Another relatively quick and simple fix for the problem is to open the task manager and check if your script is still somehow running in the background. If it is, close the process and then try running your script again. 

Keep in mind while this may get your script running, it’s not a fix, as the errors that the compiler pointed out still exist and can cause your programs to crash or stop working suddenly. 

Also read: Google Pay referral code: Everything you need to know

nv-author-image

Yadullah Abidi

Someone who writes/edits/shoots/hosts all things tech and when he's not, streams himself racing virtual cars. You can contact him here: [email protected]

>