PlaySound linker error in C++
- by logic-unit
Hello,
I'm getting this error:
[Linker error] undefined reference to 'PlaySoundA@12' Id returned 1 exit status
From this code:
// c++ program to generate a random sequence of numbers then play corresponding audio files
#include <windows.h>
#include <mmsystem.h>
#include <iostream>
#pragma comment(lib, "winmm.lib")
using namespace std;
int main()
{
int i;
i = 0; // set the value of i
while (i <= 11) // set the loop to run 11 times
{
int number;
number = rand() % 10 + 1; // generate a random number sequence
// cycling through the numbers to find the right wav and play it
if (number == 0)
{
PlaySound("0.wav", NULL, SND_FILENAME); // play the random number
}
else if (number == 1)
{
PlaySound("1.wav", NULL, SND_FILENAME); // play the random number
}
//else ifs repeat to 11...
i++; // increment i
}
return 0;
}
I've tried absolute and relative paths for the wavs, the file size of them is under 1Mb each too. I've read another thread here on the subject:
http://stackoverflow.com/questions/1565439/how-to-playsound-in-c
As you may well have guessed this is my first C++ program, so my knowledge is limited with where to go next. I've tried pretty much every page Google has on the subject including MSDN usage page.
Any ideas?
Thanks in advance...