1

I just finished installing GLFW for C++ in order to work with OpenGL, and when I run the following code:

#include <stdlib.h>
#include <GL/glfw.h>

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

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

, it throws the following error:

Error:
build/Debug/MinGW-Windows/main.o: In function `main':
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:8: undefined reference to `glfwInit'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:11: undefined reference to `glfwOpenWindow'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:13: undefined reference to `glfwTerminate'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:22: undefined reference to `glfwSwapBuffers'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:24: undefined reference to `glfwGetKey'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:24: undefined reference to `glfwGetWindowParam'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:27: undefined reference to `glfwTerminate'

And yes, I have linked opengl32.lib into my project.

genpfault
  • 51,148
  • 11
  • 85
  • 139
CoderTheTyler
  • 839
  • 2
  • 11
  • 30
  • 1
    I am not using codeblocks though. That environment specifically allows the creation of a GLFW project unlike NetBeans (and I'd rather not switch IDEs). Unless Netbeans has a way to do this? – CoderTheTyler Feb 09 '13 at 02:11
  • The same things apply though, OpenGL is not GLFW - linking opengl32.lib is not enough. – us2012 Feb 09 '13 at 02:12
  • Then what do I link besides that? I have already gone through that entire process. Is there another lib file I have to directly link to with my project? – CoderTheTyler Feb 09 '13 at 02:13
  • GLFW.lib, available from the GLFW sourceforge site, easily found via google or in the first answer in the question that I linked you to. – us2012 Feb 09 '13 at 02:15
  • I have already tried that. It gives me a much larger error. I guess I should mention I am using minGW as well. But ya, whenever I try using that lib it breaks the code even more. – CoderTheTyler Feb 09 '13 at 02:17
  • 2
    Well then you need the `mingw` libs - this is exactly what the first answer in the question I linked to (hint hint) explains in detail (libglfw.a and libglfwdll.a). You will also need an opengl32 library that works with minGW, but I assume you took care of that already?! – us2012 Feb 09 '13 at 02:19
  • Lol sorry if I've been coming off as a jerk, but I already threw libglfw.a and libglfwdll.a into the lib folder of mingw and put the dll into the System32 folder. I also linked the opengl32 into my project which works (I tested it with freeGLUT). It is just when I add the GLFW.lib, I get worse errors than before. – CoderTheTyler Feb 09 '13 at 02:22
  • Hmmm. I'm out of ideas in that case, sorry. (You shouldn't need GLFW.lib with mingw, just the .a files.) – us2012 Feb 09 '13 at 02:24
  • Well alright. Thanks for the help anyway – CoderTheTyler Feb 09 '13 at 02:25
  • Show your compile command line. –  Feb 09 '13 at 02:41

0 Answers0