C++ Undefined reference to MIDI function

こ雲淡風輕ζ 提交于 2019-12-31 07:34:06

问题


I simply want to print the amount of connected MIDI inputs. What in the world am I doing wrong?

Using Code::Blocks and GNU GCC Compiler.

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

int main() {
    printf("%d", midiInGetNumDevs());
    return 0;
}

I get undefined reference to `midiInGetNumDevs@0' upon compiling.

midiInGetNumDevs


回答1:


You need to link with with winmm.lib. In Visual Studio, you do this by adding it to the Additional Dependencies in your project properties.

Right-click on the project, select Properties, then Linker, then Input. Add winmm.lib to the list of files in Additional Dependencies.

Edit: just noticed you are using GCC. In this case, maybe the solution linked in the comments would be better. Add #pragma comment(lib, "winmm.lib") after your headers.




回答2:


If you do take a look at midiInGetNumDevs you will see that it requires Winmm.lib. You will need to add it to your projects so that the function can get linked to it.



来源:https://stackoverflow.com/questions/19483083/c-undefined-reference-to-midi-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!