Init no-go! this should be super easy

Just doing the super-basics here, getting GLFW3 initialized. Surprisingly using the suggested site code, I can’t compile (or maybe it is) and a linker issue. Probably compile settings/library/IDE IDK, but it should be very straightforward.
Repost the suggested init code, followed my compile errors. Any help would be greatly appreciated !!

g++ -std=c++0x -std=c++11 "-IC:\\bil_inc_lib\\include" "-includeC:\\bil_inc_lib\\include\\glfw3.h" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\main.o" "..\\src\\main.cpp" 
g++ "-LC:\\bil_inc_lib\\library" -o GLFW_test_prog.exe "src\\main.o" -lglfw3 -lopengl32 

Init Code:

#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

Errors:

C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x3f6): undefined reference to `CreateDCW@16'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x40b): undefined reference to `GetDeviceCaps@8'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x420): undefined reference to `GetDeviceCaps@8'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x43d): undefined reference to `DeleteDC@4'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x5db): undefined reference to `CreateDCW@16'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x5f2): undefined reference to `GetDeviceCaps@8'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x60b): undefined reference to `GetDeviceCaps@8'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x62c): undefined reference to `DeleteDC@4'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xba6): undefined reference to `CreateDCW@16'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xbbb): undefined reference to `GetDeviceGammaRamp@8'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xbc6): undefined reference to `DeleteDC@4'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xe35): undefined reference to `CreateDCW@16'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xe46): undefined reference to `SetDeviceGammaRamp@8'
C:\bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xe51): undefined reference to `DeleteDC@4'
C:\bil_inc_lib\library/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xc1): undefined reference to `CreateDIBSection@24'
C:\bil_inc_lib\library/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x10e): undefined reference to `CreateBitmap@20'
C:\bil_inc_lib\library/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x1a9): undefined reference to `DeleteObject@4'
C:\bil_inc_lib\library/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x1b4): undefined reference to `DeleteObject@4'
C:\bil_inc_lib\library/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x239): undefined reference to `DeleteObject@4'
C:\bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x151): undefined reference to `SwapBuffers@4'
C:\bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x424): undefined reference to `DescribePixelFormat@16'
C:\bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x4fb): undefined reference to `DescribePixelFormat@16'
C:\bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x635): undefined reference to `DescribePixelFormat@16'
C:\bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x656): undefined reference to `SetPixelFormat@12'
C:\bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x105d): undefined reference to `ChoosePixelFormat@8'
C:\bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1070): undefined reference to `SetPixelFormat@12'
collect2.exe: error: ld returned 1 exit status

Added gdi32 to library, problem(s) solved.

Why do we need more than the header though in this case?

MinGW never added gdi32 to the set of default libraries, unlike Visual Studio. It’s briefly mentioned here but that should probably be more prominent. Alternatively GLFW should load it dynamically like it does with system libraries not in the Visual Studio defaults.

1 Like