4

I am using code::blocks IDE which runs on GNU GCC compiler. In my project I want to play a .wav sound file in C. I tried to play a .wav sound file with a function called PlaySound. When I compiled the code code::blocks gave me an error - PlaySoundA not declared. My code is-

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

int main(int argc, char *argv[])
{
  PlaySound("C:\Snakes and Ladders\snake.wav",NULL,SND_SYNC | SND_LOOP | SND_FILENAME);
  return 0;
}

I checked my path twice. I read about this function on the internet and as per me I am using it in the correct way.

In Google, I read that the function exists in a file called winmm.lib. So I put a line of code after all the headers. It was-

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

I also added the name winmm.lib to the additional dependencies of code::blocks. So now when I compile the code it gives me another error - winmm.lib not found. Can somebody please tell me how to use PlaySound correctly.

4

2 回答 2

3
  1. 删除杂注注释
  2. 双反斜杠。反斜杠是转义字符
  3. 使用 winmm 库编译。使用 MinGW,命令如下所示:

    gcc foo.c -o foo.exe -lwinmm

于 2018-06-07T20:40:57.133 回答
0

转到设置 - 编译器... - 链接器设置。在其他链接器选项的右侧写下:-lwinmm

于 2021-01-28T16:57:58.737 回答