GLFW - Failed To Open A Window [duplicate]
Asked Answered
F

1

22

As my hunt for a cross-platform framework/library went in progress, GLFW was mentioned many times. So, I decided to try it out. Now, it seems as though I can't even init a window. :-/

#include <cstdlib>
#include <ctime>
#include <gl/glfw.h>

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);
}

I typed this in MVC++ 2010, linked the header, and 2 lib files (and it had 1 DLL file, so I threw that into the SysWOW64 folder), and I get these errors:

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 ==========

I understand the first few with the random colors, but the ones after that make no sense to me. Any idea what's wrong with this?

I'm pretty sure that I have linked the libs correctly. I place them into the C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib directory and even linked them to my C:\SDK\GLFW\glfw-2.7.bin.WIN32\lib-msvc100\debug directory.

The GLFW package was a .zip file, so I just extracted it to my default SDK folder (for all my APIs and other stuff). So the C:\SDK\GLFW is my default for GLFW.

Fagaly answered 13/4, 2011 at 0:33 Comment(0)
A
61

You need to link to opengl32.lib.

For that, as pictured below, go to Project Setting and then Linker > input > Additional Dependencies and add opengl32.lib there (use ; to separate different libs).

Note that you don't actually need to have opengl32.lib file anywhere. Visual Studio knows where to find it.

Linking to extra libs in Visual Studio

Edit: I should note that you don't need to do anything except adding opengl32.lib. That other stuff is irrelevant. Additionally, if both are present, try swapping the order, which matters in some cases.

Amoakuh answered 13/4, 2011 at 0:38 Comment(4)
link to opengl32.lib except with opengl32.lib? It's the same thing. :P But thanks! It worked now! :DFagaly
Oh, no - I was referring to the picture when I said that. I put the picture up as a demonstration, but since I don't have VS on this computer I couldn't take a screenshot myself.Amoakuh
To everyone still fustrated as hell and new to c++ like me. opengl32.lib doesnt need to be located in your library folder you refrenced, (if you have SDK installed that is... which you properbly have)Cruzcruzado
@JohnChadwick, This really helped me! Thanks a lot to point it out :)Centrum

© 2022 - 2024 — McMap. All rights reserved.