0

I am trying to make a simple C++ program that plays music, but I'm getting this error.

undefined reference to __imp_PlaySoundA'

From what I read I found out that I don't have any source code that implements PlaySound. I know I should add a reference to winmm.lib to my linker, but I only found how to do this in VisualStudio. Is there a way how to do it in CLion? I'm not even sure if CLion has something like that.

#include <iostream>
#include <windows.h>

int main() {  
    PlaySound("file_name.mp3", nullptr, SND_FILENAME | SND_ASYNC);
    return 0;
}

This doesn't help:

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

  • I am voting to reopen this question, as the question has been incorrectly closed as a duplicate, in my opinion. The OP states that they want instructions for **configuring CLion** to pass a certain library to the linker. They do not want general information on the reason why libraries have to be passed to the linker. – Andreas Wenzel Oct 17 '20 at 02:00
  • Try https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html#link-libs – zdenek Oct 17 '20 at 16:42

1 Answers1

1

I have already solved it, you need to add winMM.Lib to the CMake file. Plus the file can't be .mp3 but .wav (maybe some others, I did't try).

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