2011-04-13 226 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