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
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
#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
#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.