Search code examples
c++cmakeclionjetbrains-ide

Link winmm.lib to CLion using CMake


I am trying to play music in my C++ project, but I'm getting undefined reference error. I know it was already answered here, but that doesn't help me at all:

What is an undefined reference/unresolved external symbol error and how do I fix it?

I know how to fix it in VisualStudio, by adding a reference to winmm.lib to my linker. Is there a way how to do it in CLion? I tried adding it to my CMake list, but it still doesn't work, because I don't really know how to do that.

# Path to WinMM.Lib
link_directories(C:\\Program Files \(x86\)\\Windows Kits\\10\\Lib\\10.0.18362.0\\um\\x64)

# Link to GLFW, GLEW and OpenGL
target_link_libraries(template PUBLIC
        ${GLFW_LIBRARIES}
        ${GLEW_LIBRARIES}
        ${OPENGL_LIBRARIES}
        ${winMM.Lib})

Solution

  • As @arrowd said, winMM isn't a variable,so CMake file should look like this.

    # Link to GLFW, GLEW and OpenGL
    target_link_libraries(template PUBLIC
            ${GLFW_LIBRARIES}
            ${GLEW_LIBRARIES}
            ${OPENGL_LIBRARIES}
            winMM.Lib)