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

3

13

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
Elecampane answered 19/10, 2019 at 2:38 Comment(3)
How are you building the program?Bochum
LNK2019 is a linker error, not a compile error. So the code is almost irrelevant. When you us glad then you've to compile "glad.c" and to link the resulting object file.Dulce
add glad.c in you project folderEusporangiate
N
51

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

Nudism answered 20/10, 2019 at 1:54 Comment(1)
thanks a ton, I added the file via explorer folder and thought it'll detect lol.Subcutaneous
K
1

You should actually add the glad.c file that came in the 'src' directory of GLAD.

Kairouan answered 24/7, 2023 at 1:2 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Plesiosaur
D
0
  1. Navigate to the glad/src folder via the explorer.
  2. Simply drag and drop glad.c inside your Source Files of Visual Studio.

enter image description here

Deferment answered 3/2 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.