【问题标题】:How to fix "unresolved external symbol _gladLoadGLLoader referenced in function _main" and "unresolved external symbol _glad_glViewport"?如何修复“函数_main中引用的未解析的外部符号_gladLoadGLLoader”和“未解析的外部符号_glad_glViewport”?
【发布时间】:2020-02-15 23:53:05
【问题描述】:

我在构建程序时不断收到未解决的外部符号错误。但是,程序编译得很好。我正在使用 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);
}

我不断收到相同的 2 个错误:

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

Main.obj : error LNK2001: unresolved external symbol _glad_glViewport

【问题讨论】:

  • 你是如何构建程序的?
  • LNK2019 是链接器错误,而不是编译错误。所以代码几乎是无关紧要的。当您感到高兴时,您必须编译“glad.c”并链接生成的目标文件。
  • 在你的项目文件夹中添加glad.c

标签: c++ opengl glfw glad


【解决方案1】:

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

【讨论】:

  • 你是我的英雄。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-04
  • 1970-01-01
  • 2013-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多