I'm using the minGW compiler to make a C++ program that plays a song file in loop in the background for a game. I pass this into the command prompt : D:\project g++ music.cpp
And the error I get is:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\ccQ5qzuQ.o:music.cpp:(.text+0x2e): undefined reference to `PlaySoundA@12' collect2.exe: error: ld returned 1 exit status**
What am I doing wrong? I can't find any clear explanation for this for minGW (not visual studio). Any help is appreciated!!
The code is:
#include <iostream>
#include <windows.h>
int main() {
PlaySound(TEXT("blue.wav"), NULL, SND_SYNC);
system("pause");
return 0;
}```
The "undefined reference to PlaySoundA
suggests that you are not including the right library into your project. It requires: Mmsystem.h (include Windows.h) Winmm.lib Winmm.dll.
Steps to add a library in Code::Blocks are:
Make sure the .dll is included in your path environment variable.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments