0

I am trying to compile this test program from glfw's docs:

//test.c

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

However when I attempt to compile it, I am given this list of errors:

//usr/local/lib/libglfw3.a(monitor.c.o): In function `glfwSetGamma':
monitor.c:(.text+0x1597): undefined reference to `pow'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `_glfwCreateCursor':
x11_init.c:(.text+0x11a): undefined reference to `XcursorImageCreate'
x11_init.c:(.text+0x190): undefined reference to `XcursorImageLoadCursor'
x11_init.c:(.text+0x19b): undefined reference to `XcursorImageDestroy'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `_glfwPlatformInit':
x11_init.c:(.text+0x317): undefined reference to `XF86VidModeQueryExtension'
x11_init.c:(.text+0x3d3): undefined reference to `XineramaQueryExtension'
x11_init.c:(.text+0xfad): undefined reference to `XineramaIsActive'
//usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x3ea): undefined reference to `XineramaQueryScreens'
//usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetGammaRamp':
x11_monitor.c:(.text+0xdf4): undefined reference to `XF86VidModeGetGammaRampSize'
x11_monitor.c:(.text+0xe21): undefined reference to `XF86VidModeGetGammaRamp'
//usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformSetGammaRamp':
x11_monitor.c:(.text+0xf48): undefined reference to `XF86VidModeSetGammaRamp'
collect2: error: ld returned 1 exit status

Here's the command line input I used:

gcc test.c -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi -ldl -o test

My glfw library was compiled from source using cmake.

I have been stuck on this issue for the past few days, so some help will be appreciated.

  • You are not linking the libraries that the missing symbols are defined in. `Xcursor*` requires `-lXcursor`. `XF86VidMode*` requires `-lXxf86vm`. `Xinerama*` requires `-lXinerama`. Since `libglfw3.a(x11_init.c.o)` is the file making all these references, the additional required libraries must all be input after `-lglfw3` – Mike Kinghan May 15 '20 at 22:46
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mike Kinghan May 15 '20 at 22:46
  • Thank you Mike Kinghan! I have linked the required libraries and now the program compiles and runs without error. Thank you! – German Empire Ball May 15 '20 at 23:14

0 Answers0