I was trying to compile an example code, but couldn’t get past a linking error.
main.cpp(this code is from glfw documentation page):
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
.
.
I am getting two different linker errors:
-
One is very large(multiple undefined type errors) and occurs when I link
libglfw3.a
fromlib-mingw-w64
folder. -
The 2nd error is of single line:
undefined reference to '__imp_glClear'
it occurs when I link either:
libglfw3dll.a
FROMlib-mingw-w64
FOLDER or,
glfw3.dll
FROMlib-static-ucrt
FOLDER
Removing the line glClear(GL_COLOR_BUFFER_BIT);
from the while loop in main.cpp seems to get rid of the 2nd error and successfully compile. And it even gives a simple window when run.
.
.
However, this doesn’t feel right. Deleting a function to stop linker error.
I am new to opengl, glfw and am very clueless about any of the linking stuff so please bear with me. I just can’t figure out, am I forgetting something else to link? Or change some compiler settings maybe?
.
.
Details about the system:
Pre compiled glfw 64 bit windows library
Code blocks (empty project as the template)
msys64 mingw compiler