Basic Program Undefined Reference to symbo 'dlclose@@GLIBC


I’m trying to get up and running with GLFW and haven’t had much luck. I’m on Linux Mint using GCC 7.3.0.

I cloned the GLFW repo, built the libraries, and ran make install.

Now I have a simple CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)


set(GLFW_DIR /usr/local/lib/cmake/glfw3)

add_executable(hello-glfw hello-glfw.cpp)

find_package(glfw3 REQUIRED)

find_package(OpenGL REQUIRED)

target_link_libraries(hello-glfw OpenGL glfw3)

I can run CMake from here, no problems.
My source code (hello-glfw.cpp) is just copy-pasted from one of the GLFW guides):

#include <GL/glut.h>
#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)
        return -1;

    /* Make the window's context current */

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
        /* Render here */

        /* Swap front and back buffers */

        /* Poll for and process events */

    return 0;

The above code gives me an error: undefined reference to symbol ‘dlclose@GLIBC_2.2.5’.
A few minutes of google searching told me to include the ‘dl’ library. I updated my target_link_libraries to:

target_link_libraries(hello-glfw dl OpenGL glfw3)

But I’m still getting the error.

Any thoughts?

Thanks in advance!

There’s a section on compiling with Cmake and installed GLFW binaries in the documentation.

From what I can see the only error you have is that you should link to glfw rather than glfw3. Try this and if you still have issues come back to this thread.

I know you state that you added the dl lib in cmake, can you explicitly try this variable? It might include more dependencies:
target_link_libraries(hello-glfw ${CMAKE_DL_LIBS} OpenGL glfw3)