5

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
Steve Rowe
  • 19,411
  • 9
  • 51
  • 82
user3178851
  • 61
  • 1
  • 1
  • 5

2 Answers2

15

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.

Xantium
  • 11,201
  • 10
  • 62
  • 89
Steve Rowe
  • 19,411
  • 9
  • 51
  • 82
  • Not sure why, but adding to the linker properties didn't work for me, but adding to the cpp source code did #pragma comment (lib, "winmm.lib") – David Mar 30 '22 at 06:32
3

You did not link in the required library.

Assuming this is the Windows PlaySound function you're talking about, the documentation states that your project requires Winmm.dll for this function.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055