0

So, I'm trying to run Playsound using code from here,

How to PlaySound in C++ using Windows API?

So following advice from here, https://stackoverflow.com/a/41909627/13519865

I added these lines to cmake

find_library(TEST_LIB winmm lib)
target_link_libraries(drum_kit LINK_PUBLIC "${TEST_LIB}")

But I'm getting these error

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
TEST_LIB
    linked by target "drum_kit" in directory C:/Users/Cyber/CLionProjects/drum_kit

It is clear that I'm not linking the library properly, how it should be actually done, can anyone help me?

Cyber Avater
  • 1,494
  • 2
  • 9
  • 25
  • The error message tells you that `find_library` has **failed to find** the requested library. (This is why `TEST_LIB` variable has be set to NOTFOUND value). Note, that by default `find_library` searches only standard system locations. If you want to search other places, you need to pass additional parameters to `find_library` or set some variables which affects on search algorithm. What is the **exact path** to your library, including the name of the library file? By knowing the path we could help you to construct `find_library` call which finds the library. – Tsyvarev Apr 13 '22 at 00:01
  • Hi, thanks for responding. I actually have little experience with C and 0 with CMake. -What is the exact path to your library? I haven't actually downloaded any library. The MinGW is bundled with Clion itself. (location C:\Program Files (x86)\JetBrains\CLion 2021.3.4\bin\mingw) - including the name of the library file? The library name is winmm, I think. Again, thanks for reaching out. – Cyber Avater Apr 13 '22 at 06:17
  • You show the path with location of MinGW. I asked you the path to the **library** which you search. that is `winmm`. The library file is one you see in a filesystem, e.g. `winmm.lib`. BTW, if you want just to pass `-lwinmm` flag to the linker, then use `target_link_libraries(drum_kit PUBLIC winmm)`. In that case there is no needs to search the library in CMake script. – Tsyvarev Apr 13 '22 at 08:05
  • Yes, as you can see, I'm totally a noob here. I don't know where "winmm.lib" exists (I haven't downloaded any). Adding `target_link_libraries(drum_kit PUBLIC winmm)` I was able to play the .wav file, Thank you so much. But why I didn't need to search the library in CMake script? This guy here provided the path it seems https://stackoverflow.com/q/64400050/13519865 which is useless? Thanks again. – Cyber Avater Apr 13 '22 at 08:45

0 Answers0