Glew - 与 GLFW 配对时 gl- 函数符号上出现链接错误

Glew - Linking Error on gl- function symbols when paired with GLFW

本文关键字:符号 错误 链接 函数 gl- GLFW Glew      更新时间:2023-10-16

我正在重新设计一个项目以使用 GLFW 而不是 FreeGLUT 来,我想我一定设法在我的链接器设置中删除了一些东西。我正在使用 GLEW,虽然我最初认为我已经以某种方式解开了它,但它并没有给我所有与 GLEW 相关的函数调用的错误,只有几个。我已经检查了我使用 git 对属性文件所做的更改,唯一的更改是将freeglut.lib替换为glfwdll.lib

错误消息:

1>main.obj : error LNK2019: unresolved external symbol __imp__glBlendFunc@8 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glDepthFunc@4 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function _main
1>Renderer.obj : error LNK2019: unresolved external symbol __imp__glBindTexture@8 referenced in function "public: void __thiscall Renderer::Render(unsigned int const &,unsigned int const &,struct RenderVariables const &,unsigned int const &,unsigned int const &)" (?Render@Renderer@@QAEXABI0ABURenderVariables@@00@Z)
1>Sprite.obj : error LNK2001: unresolved external symbol __imp__glBindTexture@8
1>Renderer.obj : error LNK2019: unresolved external symbol __imp__glDrawArrays@12 referenced in function "public: void __thiscall Renderer::Render(unsigned int const &,unsigned int const &,struct RenderVariables const &,unsigned int const &,unsigned int const &)" (?Render@Renderer@@QAEXABI0ABURenderVariables@@00@Z)
1>Sprite.obj : error LNK2019: unresolved external symbol __imp__glGenTextures@8 referenced in function "public: bool __thiscall Sprite::loadSprite(char *)" (?loadSprite@Sprite@@QAE_NPAD@Z)
1>Sprite.obj : error LNK2019: unresolved external symbol __imp__glGetFloatv@8 referenced in function "public: bool __thiscall Sprite::loadSprite(char *)" (?loadSprite@Sprite@@QAE_NPAD@Z)
1>Sprite.obj : error LNK2019: unresolved external symbol __imp__glTexImage2D@36 referenced in function "public: bool __thiscall Sprite::loadSprite(char *)" (?loadSprite@Sprite@@QAE_NPAD@Z)
1>Sprite.obj : error LNK2019: unresolved external symbol __imp__glTexParameterf@12 referenced in function "public: bool __thiscall Sprite::loadSprite(char *)" (?loadSprite@Sprite@@QAE_NPAD@Z)
1>Sprite.obj : error LNK2019: unresolved external symbol __imp__glTexParameteri@12 referenced in function "public: bool __thiscall Sprite::loadSprite(char *)" (?loadSprite@Sprite@@QAE_NPAD@Z)

然后,我的main((函数,这是在过渡期间最终更改的唯一函数:

void main(int argc, char** argv) 
{
if (!glfwInit())
{
    exit(-1);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
GLFWwindow* window = glfwCreateWindow(width, height, "Space Invaders", NULL, NULL);
if (window == NULL)
{
    std::cout << "Failed to create GLFW window" << std::endl;
    glfwTerminate();
    endGame(-1);
}
glfwMakeContextCurrent(window);
glViewport(0, 0, width, height);
// A call to glewInit() must be done after GLFW is initialized!
GLenum res = glewInit();
// Check for any errors
if (res != GLEW_OK) {
    fprintf(stderr, "Error: '%s'n", glewGetErrorString(res));
    endGame(1);
}
gameState = new GameState();
init();
while (!glfwWindowShouldClose(window))
{
    pollInput(window);
    display();
    glfwSwapBuffers(window);
    glfwPollEvents();
}
endGame(0);
}

我注意到每个抛出错误的函数都有 gl- 前缀而不是 glew-,现在我没有使用 freeglut 我需要添加另一个库吗?我目前只链接 glfw 和 glew。

好的,我不确定以前没有它是如何管理的,但我也需要链接OpenGL32.lib

相关文章: