playsound returning weird error

I keep getting a weird error when playing a song.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <algorithm>
#include <locale>
#include <windows.h>

#include "coordsys.h"

//Some miscellaneous functions that aren't called yet

int main()
{
PlaySound("MUSIC.WAV", NULL, SND_LOOP | SND_ASYNC | SND_FILENAME);
srand(time(0));
int diff = 0;
while (diff < 1 || diff > 5)
{
    cout << "Please select difficulty, from 1 (Trainee) to 5 (Insane):\n";
    cin >> diff;
    if (diff < 1 || diff > 5)
    cout << "Invalid difficulty! ";
}
getPlayerChoice();



undefined reference to 'PlaySoundA@12'

Last edited on
You need to add Winmm.lib to your project.
Where is that? Do I need to download it? Do I just need to include it?
It's part of the Windows SDK and should come with your compiler / IDE.
How to add it depends on what IDE you use. In Visual Studio you just add
#pragma comment(lib, "Winmm.lib")
That didn't do it.
Do you know how to do it in Code::Blocks?
Last edited on
closed account (E0p9LyTq)
With a quick internet search:

https://stackoverflow.com/questions/5862757/how-do-i-link-to-a-library-with-codeblocks

With code::blocks the library is likely named libwinmm.a not winmm.lib.
Thanks for the libwinmm.a tip Furry! It works now!
And eec - you don't need the absolute path - just make sure the file is in the same folder as the EXE.
it won't work until you add Winmm.lib to your project, this way you won't get those errors. It's pretty important to detect those kind of errors and fix them as quick as possible and I recommend you using some program such as checkmarx or others if it's getting too hard for you. Just make sure you maintain code security within you code.
Good luck.
Ben.
Topic archived. No new replies allowed.