Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "unresolved external symbol _gladLoadGLLoader referenced in function _main" and "unresolved external symbol _glad_glViewport"?

I keep getting the unresolved external symbol' error when building the program. However, the program compiles fine. I'm using the GLFW and GLAD libraries.

#include <glad/glad.h>
#include <GLFW/glfw3.h>

#include <iostream>

void framebuffer_size_callback(GLFWwindow* window, int width, int height);

//#undef main
int main() {
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    GLFWwindow* window = glfwCreateWindow(800, 600, "LearningOpenGL", NULL, NULL);

    if (window == NULL) {
        std::cout << "Failed To Create Window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);

    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
        std::cout << "Failed to initialize GLAD" << std::endl;
        return -1;
    }

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

    glViewport(0, 0, 800, 600);

    glfwTerminate();
    return 0;
}

void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
    glViewport(0, 0, width, height);
}

I keep getting the same 2 errors:

Main.obj : error LNK2019: unresolved external symbol _gladLoadGLLoader referenced in function _main

Main.obj : error LNK2001: unresolved external symbol _glad_glViewport
like image 914
Pixelated_Hacker Avatar asked Oct 19 '19 02:10

Pixelated_Hacker


People also ask

How do I fix unresolved external symbol?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

What causes unresolved external symbol?

The compiler can identify when a symbol isn't declared, but it can't tell when the symbol isn't defined. It's because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error.


1 Answers

go to project name -> add -> existing item and then add glad.c

like image 123
Nick Avatar answered Sep 24 '22 01:09

Nick