C++ – GLFW compiling undefined reference to

cglewglfw

I am getting undefined references when I try compiling my simple OpenGl program but I don't know why, I though I had everything setup right but I guess not. Can someone help me with my issue please?

My Code:

#include <GL\glew.H>
#include <GLFW\glfw3.h>

int         windowWidth  = 980;
int         windowHeight = 640;

int Main()
{
    if (!glfwInit())
        return -1;

    glfwWindowHint(GLFW_SAMPLES, 4); // AA
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = NULL;

    window = glfwCreateWindow(windowWidth, windowHeight, "Window", NULL, NULL);

    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window);
}

Console message:

"/C/Development/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/Callum/Documents/NetBeansProjects/Game'
"/C/Development/MinGW/msys/1.0/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/game.exe
make.exe[2]: Entering directory `/c/Users/Callum/Documents/NetBeansProjects/Game'
mkdir -p dist/Debug/MinGW-Windows
g++     -o dist/Debug/MinGW-Windows/game build/Debug/MinGW-Windows/main.o -L../../../../../Development/glew\ 1.11.0/lib -L../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw -lglew32 -lglfw3
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(window.c.obj):window.c:(.text+0x5fa): undefined reference to `glClear@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0x41): undefined reference to `glGetIntegerv@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0xb8): undefined reference to `glGetString@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0x608): undefined reference to `glGetString@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0x76f): undefined reference to `glGetIntegerv@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0x7b9): undefined reference to `glGetIntegerv@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0x856): undefined reference to `glGetIntegerv@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x30a): undefined reference to `_imp__CreateDCW@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x356): undefined reference to `_imp__GetDeviceCaps@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x3a2): undefined reference to `_imp__DeleteDC@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x7b): undefined reference to `_imp__CreateDCW@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x91): undefined reference to `_imp__GetDeviceGammaRamp@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x9d): undefined reference to `_imp__DeleteDC@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x35b): undefined reference to `_imp__CreateDCW@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x36d): undefined reference to `_imp__SetDeviceGammaRamp@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x379): undefined reference to `_imp__DeleteDC@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x13b): undefined reference to `_imp__DescribePixelFormat@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x926): undefined reference to `_imp__DescribePixelFormat@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xa5e): undefined reference to `_imp__DescribePixelFormat@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xa80): undefined reference to `_imp__SetPixelFormat@12'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xbaf): undefined reference to `_imp__wglMakeCurrent@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xbca): undefined reference to `_imp__wglGetProcAddress@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x10d1): undefined reference to `_imp__wglCreateContext@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x10ff): undefined reference to `_imp__wglShareLists@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1337): undefined reference to `_imp__wglDeleteContext@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x14d1): undefined reference to `_imp__wglMakeCurrent@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1503): undefined reference to `_imp__wglMakeCurrent@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1542): undefined reference to `_imp__SwapBuffers@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x165d): undefined reference to `_imp__wglGetProcAddress@4'
c:/development/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/game.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/Callum/Documents/NetBeansProjects/Game'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/Callum/Documents/NetBeansProjects/Game'
make.exe": *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 3s)

Here are some screenshots of my setup:

http://imgur.com/wqKPVk0,wMgRJR6,mprtp7c,eG8DNug,Qc8Vafp,BLguFq4,l9FXzme

Best Answer

You need to link to the OpenGL library: libopengl32.a, so you want to add either -lopengl32 to your build command, or opengl32 to your IDE's libraries. You should also link to gdi32 as well. (-lgdi32)

Source: http://www.glfw.org/docs/latest/build.html#build_link

Related Topic