Glew - 与GLFW配对时gl-功能符号的链接错误

时间:2018-01-28 23:02:56

标签: c++ glfw glew

我正在重新设计一个使用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。

1 个答案:

答案 0 :(得分:1)

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