C++ winmm library problem cant play sound
Hi everyone,
I am new to C++ and I am struggling to get CodeLite to compile and play a sound in my program I am using these libraries: -
#include <iostream>
#include <windows.h>
#include <Mmsystem.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
Trying to execute the below in my main function: -
PlaySound(TEXT("winner.wav"), NULL, SND_SYNC);
I get this error in the compiler: -
Code: Select all
C:/mingw64/bin/mingw32-make.exe -j20 -e -f Makefile
"----------Building project:[ Lottery22Dec2024 - Debug ]----------"
mingw32-make[1]: Entering directory 'C:/Users/reube/Workspaces/Lottery22Dec2024/Lottery22Dec2024'
C:/mingw64/bin/g++.exe -c "C:/Users/reube/Workspaces/Lottery22Dec2024/Lottery22Dec2024/main.cpp" -O0 -gdwarf-2 -Wall -o ../build-Debug/Lottery22Dec2024/main.cpp.o -I. -I.
C:/Users/reube/Workspaces/Lottery22Dec2024/Lottery22Dec2024/main.cpp:8: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
8 | #pragma comment(lib, "winmm.lib")
C:/mingw64/bin/g++.exe -o ..\build-Debug\bin\Lottery22Dec2024.exe @../build-Debug/Lottery22Dec2024/ObjectsList.txt -L. -static
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../build-Debug/Lottery22Dec2024/main.cpp.o: in function `main':
C:/Users/reube/Workspaces/Lottery22Dec2024/Lottery22Dec2024/main.cpp:25:(.text+0x25): undefined reference to `__imp_PlaySoundA'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Lottery22Dec2024.mk:83: ..\build-Debug\bin\Lottery22Dec2024.exe] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/reube/Workspaces/Lottery22Dec2024/Lottery22Dec2024'
mingw32-make: *** [Makefile:5: All] Error 2
==== build ended with errors (1 errors, 1 warnings) ===
I have spent over 2 hours researching on line people mentioning adding the winmm.lib to the compiler setting and tried everything nothing works and its driving me nuts lol. Something so simple but I cant get it working in CodeLite anyone else had this issue and able to help me? Thanks In Advance
Kind regards,
Jon