# Collect2.exe: error: ld returned 1 exit status While compiling

**URL:** <https://discourse.glfw.org/t/collect2-exe-error-ld-returned-1-exit-status-while-compiling/3020>\
**Category:** support\
**Created:** [July 29, 2026, 5:23pm UTC](https://discourse.glfw.org/t/collect2-exe-error-ld-returned-1-exit-status-while-compiling/3020 "2026-07-29T17:23:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![C\_fan\_39](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/c_fan_39/32/1082_2.png) [@C\_fan\_39](https://discourse.glfw.org/u/C_fan_39)\
**Post date:** [July 29, 2026, 5:23pm UTC](https://discourse.glfw.org/t/collect2-exe-error-ld-returned-1-exit-status-while-compiling/3020/1 "2026-07-29T17:23:28Z")

</div>

# The problem

Hello. I’m new to GLFW and I’m trying to compile a simple window program to test my GLFW but every time it reaches the compiling stage and then it fails sending a **_“collect2.exe: error: ld returned 1 exit status”_**. I have tried looking it up but other than it seems to be a linker error I haven’t found any thing.

# What could help

I need either a way of getting told what part of the linking is failing. That could be a command to tell the compiler to tell me or also an explanation on how to read the message given by the -v flag. Or a way to fix this in general

# Especifics

I’m compiling on Windows 10 with gcc 16.1.1 for windows, Downloaded from MSYS2  
the errors I get are:

- collect2.exe: error: ld returned 1 exit status
- and some times  
collect2.exe: error: ld returned 5 exit status  
but that is because I change something on the flags and creates a broken .exe

The arguments are passed as follows

```makefile
includes:= -I./Libs/glfw-3.4.bin.WIN64/include
build:
	gcc -v main.c -o program.exe ${includes} ./Libs/glfw-3.4.bin.WIN64/lib-mingw-w64/libglfw3.a -lgdi32 -Wall 

```

I have downloaded the latest version of GLFW 3.4 for this project in the binary form for windows also.

# Related code

```C
#include "main.h"
void error_callback(int error, const char* description);
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);

int main(int argc, char** argv)
{
	glfwSetErrorCallback(error_callback);
	if (!glfwInit())
	{
	}
	
	GLFWwindow* window = glfwCreateWindow(400, 400, "Compilatio", NULL, NULL);
	if (!window)
	{
	}
	glfwMakeContextCurrent(window);
	glfwSetKeyCallback(window, key_callback);

	int widt, height;
	glfwGetFramebufferSize(window, &widt, &height);
	glViewport(0, 0, widt, height);game loop
	glfwSwapInterval(1);

	while (!glfwWindowShouldClose(window))
	{
		glfwSwapBuffers(window);
		glfwPollEvents();
	}
	

	glfwDestroyWindow(window);
	glfwTerminate();
	return 0;
}

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
	if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
		glfwSetWindowShouldClose(window, GLFW_TRUE);
}
void error_callback(int error, const char* description)
{
	fprintf(stderr, "Error: %s\n", description);
}

```

The .h file only includes all my includes and definitions and the .c main is the only file that references it

```C
#include <GLFW/glfw3.h>
#include <stdio.h>

```

The compiler does not give me any error other than collect2.exe: error: ld returned 1 exit status and I couldn’t find more info on that other than the normal, also other than using -v I couldn’t find a way to get any info on that

# Thanks

In advance thanks a lot for your time.

---

<div class="post-metadata">

**Author:** ![C\_fan\_39](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/c_fan_39/32/1082_2.png) [@C\_fan\_39](https://discourse.glfw.org/u/C_fan_39)\
**Post date:** [July 29, 2026, 6:59pm UTC](https://discourse.glfw.org/t/collect2-exe-error-ld-returned-1-exit-status-while-compiling/3020/2 "2026-07-29T18:59:48Z")

</div>

As an update for everyone who comes here. When I comented the line `//glViewport(0, 0, widt, height);` Now it compiles but I guess that means I got a proglem with open GL? I don’t know I’m really great full if some body can help there

---

<div class="post-metadata">

**Author:** ![C\_fan\_39](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/c_fan_39/32/1082_2.png) [@C\_fan\_39](https://discourse.glfw.org/u/C_fan_39)\
**Post date:** [July 29, 2026, 7:17pm UTC](https://discourse.glfw.org/t/collect2-exe-error-ld-returned-1-exit-status-while-compiling/3020/3 "2026-07-29T19:17:40Z")

</div>

It was a GL problem. My computer was NOT adding ANY GL implementation and the thing was crashing withouth an error. Fixing glad fixed the rest
