首页 > 解决方案 > 包括MMSystem.h

问题描述

我正在编写一个简单的 C++ 程序,我需要在其中使用MMSystem.h.

我用 编译它g++ -g .\audiodemo.cpp -o audio -lm -lwinmm,但它会引发错误

MMSystem.h:没有这样的文件或目录

我什至还没有开始mmsystem在我的代码中使用它并认为它是一个标准库。

#include <iostream>
#include <Windows.h>
#include <MMSystem.h>

using namespace std;

const int NUMPTS = 44100 * 10;   // 10 seconds
int sampleRate = 44100;
short int waveIn[NUMPTS];   // 'short int' is a 16-bit type; I request 16-bit samples below

int main(){
    PlaySound(TEXT("CantinaBand3.wav"), NULL, SND_FILENAME | SND_ASYNC);// - the correct code

    int test = 0;
    cin>>test;
    return 0;
}

标签: c++audiocompilationlinker

解决方案


如果您使用的是代码块 IDE,请先转到设置,然后单击编译器,然后转到链接器设置并将winmm添加到库部分。然后它不会显示任何错误。


推荐阅读