【问题标题】:GLFW - Failed To Open A WindowGLFW - 无法打开窗口
【发布时间】:2011-08-04 07:56:25
【问题描述】:

在我寻找跨平台框架/库的过程中,GLFW 被多次提及。所以,我决定试一试。现在,好像我什至无法初始化一个窗口。 :-/

#包括 #包括 #包括 int main(int argc, char *argv[]) { int 运行 = GL_TRUE; srand(时间(NULL)); 如果(!glfwInit()) 退出(EXIT_FAILURE); if (!glfwOpenWindow(300, 300, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) { glfw终止(); 退出(EXIT_FAILURE); } 在跑步的时候) { glClear(GL_COLOR_BUFFER_BIT); glClearColor(rand() % 255 + 1, rand() % 255 + 1, rand() % 255 + 1, 0); glfwSwapBuffers(); 运行 = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); } glfw终止(); 退出(EXIT_SUCCESS); }

我在 MVC++ 2010 中输入了这个,链接了头文件和 2 个 lib 文件(它有 1 个 DLL 文件,所以我把它放到了 SysWOW64 文件夹中),我得到了这些错误:

1>------ Build started: Project: glfwTest, Configuration: Debug Win32 ------
1> test.cpp
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(8): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(22): warning C4244: 'argument' : conversion from 'int' to 'GLclampf', possible loss of data
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(22): warning C4244: 'argument' : conversion from 'int' to 'GLclampf', possible loss of data
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(22): warning C4244: 'argument' : conversion from 'int' to 'GLclampf', possible loss of data
1>test.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function _main
1>GLFW.lib(win32_window.obj) : error LNK2001: unresolved external symbol __imp__glClearColor@16
1>test.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _main
1>GLFW.lib(window.obj) : error LNK2001: unresolved external symbol __imp__glClear@4
1>GLFW.lib(win32_window.obj) : error LNK2001: unresolved external symbol __imp__glClear@4
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglGetProcAddress@4 referenced in function _initWGLExtensions
1>GLFW.lib(win32_glext.obj) : error LNK2001: unresolved external symbol __imp__wglGetProcAddress@4
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function _createWindow
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function _createContext
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function _destroyWindow
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__glGetFloatv@8 referenced in function __glfwPlatformSetWindowSize
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__glGetIntegerv@8 referenced in function __glfwPlatformSetWindowSize
1>GLFW.lib(glext.obj) : error LNK2001: unresolved external symbol __imp__glGetIntegerv@8
1>GLFW.lib(glext.obj) : error LNK2019: unresolved external symbol __imp__glGetString@4 referenced in function __glfwParseGLVersion
1>c:\users\andrew\documents\visual studio 2010\Projects\glfwTest\Debug\glfwTest.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我理解前几个随机颜色,但后面的那些对我来说毫无意义。知道这有什么问题吗?

我很确定我已正确链接库。我将它们放入 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib 目录 甚至将它们与我的 C:\SDK\GLFW\glfw-2.7.bin.WIN32\lib-msvc100\debug 目录。

GLFW 包是一个 .zip 文件,所以我只是将它解压缩到我的默认 SDK 文件夹(用于我所有的 API 和其他东西)。所以 C:\SDK\GLFW 是我对 GLFW 的默认设置。

【问题讨论】:

    标签: opengl window glfw


    【解决方案1】:

    您需要链接到opengl32.lib

    为此,如下图所示,转到Project Setting,然后转到Linker > input > Additional Dependencies,并在那里添加opengl32.lib(使用; 分隔不同的库)。

    请注意,您实际上并不需要在任何地方都有opengl32.lib 文件。 Visual Studio 知道在哪里可以找到它。

    编辑:我应该注意,除了添加opengl32.lib,您不需要做任何事情。其他的东西是无关紧要的。此外,如果两者都存在,请尝试交换顺序,这在某些情况下很重要。

    【讨论】:

    • 链接到 opengl32.lib,除了 opengl32.lib?这是同一件事。 :P 但是谢谢!它现在起作用了! :D
    • 哦,不——我说的时候指的是图片。我把图片放上来作为演示,但是由于我这台电脑上没有VS,所以我不能自己截图。
    • 献给所有像我一样对 C++ 感到沮丧的人。 opengl32.lib 不需要位于您引用的库文件夹中,(如果您安装了 SDK,那就是......您应该拥有)
    • @JohnChadwick,这对我很有帮助!非常感谢指出:)
    猜你喜欢
    • 2014-10-19
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    相关资源
    最近更新 更多