opengl 如何修复“function _main中引用的外部symbol _gladLoadGLLoader无法解析”和“外部symbol _glad_glViewport无法解析”?

ht4b089n  于 2023-08-04  发布在  其他
关注(0)|答案(2)|浏览(144)

我不断得到未解决的外部符号'错误时,构建程序。但是,程序编译得很好。我正在使用GLFW和GLAD库。

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

字符集
我一直在重复两个错误:

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

Main.obj : error LNK2001: unresolved external symbol _glad_glViewport

f87krz0w

f87krz0w1#

转到项目名称->添加->现有项目,然后添加glad. c

i86rm4rw

i86rm4rw2#

您实际上应该添加GLAD的'src'目录中的glad.c文件。

相关问题