使用 MinGW 播放声音

Playing sound using MinGW

我想使用 mciSendString 在我的应用程序中播放声音。为此,我在 Microsoft 网站上找到了以下简单片段:

#include "stdafx.h"
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "Winmm.lib")

int _tmain(int argc, _TCHAR* argv[])
{
  mciSendString("play MyFile wait", NULL, 0, 0);
  mciSendString("close MyFile", NULL, 0, 0);
  return 0;
}

我的问题是我不使用 Visual Studio。有没有办法让这个例子通过 MinGW 编译?

一旦我删除 MSVS-isms

#include <windows.h>

int main()
{
  mciSendString("play MyFile wait", NULL, 0, 0);
  mciSendString("close MyFile", NULL, 0, 0);
  return 0;
}

并用

编译
g++ -o test.exe "src\test.o" -lwinmm

as per the linked duplicate,构建成功