2011-04-13 181 views
14

当我寻找一个跨平台的框架/库时,GLFW被多次提及。所以,我决定尝试一下。现在,似乎我甚至无法启动一个窗口。 : -/GLFW--无法打开窗口

 
#include 
#include 
#include 

int main(int argc, char *argv[]) 
{ 
    int running = GL_TRUE; 
    srand(time(NULL)); 

    if (!glfwInit()) 
     exit(EXIT_FAILURE); 

    if (!glfwOpenWindow(300, 300, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) 
    { 
     glfwTerminate(); 
     exit(EXIT_FAILURE); 
    } 

    while (running) 
    { 
     glClear(GL_COLOR_BUFFER_BIT); 
     glClearColor(rand() % 255 + 1, rand() % 255 + 1, rand() % 255 + 1, 0); 

     glfwSwapBuffers(); 

     running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); 
    } 

    glfwTerminate(); 

    exit(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 [email protected] referenced in function _main 
1>GLFW.lib(win32_window.obj) : error LNK2001: unresolved external symbol [email protected] 
1>test.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>GLFW.lib(window.obj) : error LNK2001: unresolved external symbol [email protected] 
1>GLFW.lib(win32_window.obj) : error LNK2001: unresolved external symbol [email protected] 
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function _initWGLExtensions 
1>GLFW.lib(win32_glext.obj) : error LNK2001: unresolved external symbol [email protected] 
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function _createWindow 
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function _createContext 
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function _destroyWindow 
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function __glfwPlatformSetWindowSize 
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function __glfwPlatformSetWindowSize 
1>GLFW.lib(glext.obj) : error LNK2001: unresolved external symbol [email protected] 
1>GLFW.lib(glext.obj) : error LNK2019: unresolved external symbol [email protected] 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。

回答

44

您需要链接到opengl32.lib。

像: Linking to extra libs in Visual Studio

除非opengl32.lib。

编辑:我要指出,你不需要做不同的是加入opengl32.lib任何东西。其他的东西是无关紧要的。此外,如果两者都存在,请尝试交换订单,这在某些情况下很重要。

+0

链接到opengl32.lib除了opengl32.lib?这是同一件事。 :P但是,谢谢!它现在工作! :D – Imnotanerd 2011-04-13 00:45:45

+1

哦,不 - 我说的时候是指图片。我把这张照片当成了演示,但是因为我没有在这台电脑上使用VS,所以我无法自己截图。 – 2011-04-13 00:48:23

+0

好的,谢谢你的帮助(和建议)! – Imnotanerd 2011-04-13 00:54:34