尝试使用Windows Midi API时出现gcc错误

问题描述

问题很简单,我正在尝试将Windows API用于Midi,但gcc找不到该函数的引用。我正在使用MinGW和gcc版本9.2.0。我发现类似问题的唯一解决方案是添加winmm.lib,但这也无济于事。

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccV6si7i.o: in function `main':
c:/.../test.cpp:13: undefined reference to `midiInGetNumDevs@0'
collect2.exe: error: ld returned 1 exit status

这是产生错误的C ++代码:

#include <iostream>
#include <string>

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

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

int main()
{
    MIDIINCAPS caps;

    UINT numberOfDevices = midiInGetNumDevs();
    if(numberOfDevices < 0){
        for (unsigned int i = 0; i < numberOfDevices; ++i) {
            midiInGetDevCaps(i,&caps,sizeof(MIDIINCAPS));
            std::cout << i << " : name = " << caps.szPname << std::endl;
        }
    }

    return 0;
}

解决方法

如@dxiv所述,您需要链接<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <!-- get the Value of the main_caracs that has a Label that = 'Consommation en ville' --> <xsl:value-of select="x/main_caracs[Label='Consommation en ville']/Value" /> </xsl:template> </xsl:stylesheet> 库。 GCC不了解MSVC的winmm,因此不知道它是必需的。因此,当找不到功能时,链接将失败。

查看诸如How to specify libraries paths in gcc?之类的问题以了解操作方法。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...