david
david

Reputation: 292

C++ Undefined reference to MIDI function

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

Upvotes: 0

Views: 621

Answers (2)

Chris Olsen
Chris Olsen

Reputation: 3511

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.

Upvotes: 1

Caesar
Caesar

Reputation: 9853

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.

Upvotes: 0

Related Questions