c++midilnk2001

Cannot compile RtMidi VS community 2015


I am following the basic tutorial on https://www.music.mcgill.ca/~gary/rtmidi/ and I cannot seem to make it past the first step in "Getting Started."

Originally I was only getting two errors, one of which was a "LNK2019 - unresolved external symbol" error, which I fixed by linking rtmidi.lib and rtmidid.lib

Now I have a huge block of errors that I can't make any sense of

rtmidi.lib(RtMidi.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
RTMIDI_test.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification
rtmidi.lib(RtMidi.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in RTMIDI_test.obj
rtmidi.lib(RtMidi.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in RTMIDI_test.obj
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInUnprepareHeader@12
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInOpen@20
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiOutGetDevCapsW@12
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiOutPrepareHeader@12
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiOutOpen@20
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInReset@4
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInPrepareHeader@12
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiOutUnprepareHeader@12
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInGetDevCapsW@12
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInStart@4
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInClose@4
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInAddBuffer@12
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInGetNumDevs@0
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiOutShortMsg@8
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiOutGetNumDevs@0
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiOutLongMsg@12
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiOutClose@4
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInStop@4
rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiOutReset@4
C:\Users\Zach\Desktop\RTMIDI_test\Debug\RTMIDI_test.exe : fatal error     LNK1120: 19 unresolved externals

Obviously on lines 7-25 it's looking for a library or something that doesn't exist, but gives no hints as to what it is. The rest however, I can't even begin to figure out. Any Ideas?

I read somewhere else to change the project option to "Release" Which does get rid of the above messages, but instead replaces them with

RTMIDI_test.obj : error LNK2001: unresolved external symbol "public: __thiscall RtMidiIn::RtMidiIn(enum RtMidi::Api,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,unsigned int)" (??0RtMidiIn@@QAE@W4Api@RtMidi@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@I@Z)
C:\Users\Zach\Desktop\RTMIDI_test\Release\RTMIDI_test.exe : fatal error LNK1120: 1 unresolved externals

Solution

  • Most of the link errors tell you what you need to do to fix them (at least in combination with a bit of googling)

    rtmidi.lib(RtMidi.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in RTMIDI_test.obj
    rtmidi.lib(RtMidi.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in RTMIDI_test.obj
    

    So RTMIDI_test.cpp has been compiled with a different value for _ITERATOR_DEBUG_LEVEL than in rtmidi.lib. The next line says that you are trying to link your debug project with a release build of rtmidi.lib. You should change this to link against the debug version instead which should remove some or all of the other warnings and errors.

    rtmidi.lib(RtMidi.obj) : error LNK2001: unresolved external symbol __imp__midiInUnprepareHeader@12
    

    midiInUnprepareHeader and the other midiIn* functions live in winmm.lib (see the docs), so you also need to link against that.