Anastassis Kapetanakis
Anastassis Kapetanakis

Reputation: 183

C++ PlaySound() Error

I would like to make a question as far as an application regarding music manipulation is concerned: I compile a program with the function PlaySound() but the following message shows up: [Linker error] undefined reference to `PlaySoundA@12'. I use Dev c++ to do that, because I have a problem with the visual studio and I can not sign in to my Microsoft account and does not let me to use it. Well I dont't know what is going wrong and does not let me play the sound. I include the windows.h and mmsystem.h headers and all are properly written. Can anyone help me with that?

#include <windows.h>
#include <mmsystem.h>

int main(){
    PlaySound("test.wav", NULL, SND_FILENAME);
    return 0;
}

Upvotes: 0

Views: 2374

Answers (2)

Christopher Nolan
Christopher Nolan

Reputation: 1107

Just add the following line before the main function.

#pragma comment(lib, "Winmm.lib")

Upvotes: 1

William
William

Reputation: 41

You need to link the compiler to the winmm.lib library for this to properly link.

Upvotes: 1

Related Questions