Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PlaySound in C++ [duplicate]

Tags:

c++

winapi

I'm trying to play sounds in my C++ app. We were given a guide to using XACT for it but I can't get it to work so I'm trying to use the PlaySound functions.

This is what i've tried. I've also tried it with the whole directory link to where it is saved.

 int main() { 
        PlaySound("background.mp3", NULL, SND_SYNC); 
    }

This is the errors it throws up

Error   7   error LNK2019: unresolved external symbol __imp__PlaySoundA@12 referenced in function _main C:\Users\Siyico\Desktop\Legit\w9base\wingl2013_14\SpaceGame.obj wingl2013_14

Error   8   error LNK1120: 1 unresolved externals   C:\Users\Siyico\Desktop\Legit\w9base\Debug\wingl2013_14.exe 1   1   wingl2013_14
like image 715
user3178851 Avatar asked Dec 03 '22 20:12

user3178851


1 Answers

The problem is that you don't have any source code that implements PlaySound. You need to link to a library provided by Microsoft to do that. In this case the library is winmm.lib. Thus you need to add a reference to winmm.lib to your linker settings.

To do that, right-click on your project and select properties. Then go to the linker->input item. Add ";winmm.lib" to the end of the Additional Dependencies box.

like image 176
Steve Rowe Avatar answered Dec 17 '22 15:12

Steve Rowe