playsound returning weird error

Jun 15, 2017 at 8:54pm
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 Jun 15, 2017 at 8:54pm
Jun 15, 2017 at 8:57pm
You need to add Winmm.lib to your project.
Jun 15, 2017 at 9:03pm
Where is that? Do I need to download it? Do I just need to include it?
Jun 15, 2017 at 9:40pm
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")
Jun 15, 2017 at 9:42pm
That didn't do it.
Do you know how to do it in Code::Blocks?
Last edited on Jun 15, 2017 at 10:55pm
Jun 15, 2017 at 11:20pm
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.
Jun 16, 2017 at 12:05am
Jun 16, 2017 at 1:05am
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.
Jun 16, 2017 at 6:28am
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.