OpenGL Error with glClear undefined reference to `__imp_glClear’

  c++, cmake, linker, opengl, visual-studio-code

I have some trouble with compile example of opengl Its showing me linking error but I dont know how to solve it

Summary : How to solve linking error about __imp_glClear ? (I`m using mingw64 precompiled glfw)

The code is (C++)

#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;
}

And CMakeLists.txt (Linking precompiled library of OpenGL (glfw))

cmake_minimum_required(VERSION 3.21.1)

project("OpenGLTutorial")

add_executable(${PROJECT_NAME} main.cpp)

target_include_directories(
    ${PROJECT_NAME}
    PUBLIC
    ${CMAKE_SOURCE_DIR}/include
)

link_directories(
    ${CMAKE_SOURCE_DIR}/lib
)

target_link_libraries(
    ${PROJECT_NAME}
    PUBLIC
    ${CMAKE_SOURCE_DIR}/lib/libglfw3.a
)

If i get rid of glClear(GL_COLOR_BUFFER_BIT); line Its compiled and run well however when compile with that code Its showing linking error! but i dont know what i didnt linking. HELP ME!

Source: Windows Questions C++

One Reply to “OpenGL Error with glClear undefined reference to `__imp_glClear’”

LEAVE A COMMENT