LNK2019& LNK1120未解决的外部可能很容易解决,但我遇到了麻烦

时间:2013-12-18 01:11:44

标签: lnk2019 unresolved-external

我一直在使用这些LNK2019一段时间,似乎无法找到摆脱它们的方法。我知道这些错误已经有很多线索了,但是我还没有发现任何对我有帮助的东西,所以希望有人可能会错过我可能错过的明显的东西。

我传统上没有学到很多东西,如果我的代码有点乱,那就很抱歉。

主:

#include "eventLoop.h"
#include <time.h>
#include <iostream>

using namespace std;

bool buttonA, buttonB, buttonC, buttonD, buttonE, buttonF, buttonG = false;
bool KeepProgramOpen = true;
time_t timer;
time_t oldtime;
time_t dtime;
time_t looptime;
int rate;
char Note;
bool FirstLoop = true;

eventLoop MainEventLoop;

int main()
{
    rate = 60;
    looptime = 1000 / rate;

    while(KeepProgramOpen==true)
    {

        time(&timer);
        dtime = timer-oldtime;

        if(dtime<looptime)
        {
            continue;
        }

        oldtime = timer;

        MainEventLoop.FindFinalNote(buttonA, buttonB, buttonC, buttonD, buttonE, buttonF, buttonG, FirstLoop);

        FirstLoop = false;

    //Closing stuff goes here
    }
}

eventLoop.h:

#pragma once

class eventLoop {

public:

    void FindFinalNote(bool, bool, bool, bool, bool, bool, bool, bool);

protected:

};

eventLoop.cpp:

#include "eventLoop.h"
#include "MidiOutput.h"
#include "FileIO.h"

MidiOutput MidiOutputX;

FileIO fileioX;

void eventLoop::FindFinalNote(bool A, bool B, bool C, bool D, bool E, bool F, bool G, bool firstloop)
{

    if(firstloop == true)
    {
        for (int loopindex=0; loopindex<10; loopindex++)
        {
        //  Note[loopindex] = Filecheck for notes
        }

        MidiOutputX.FindDevice(
            1,   /*int argc number of ports*/
            60,  /*char argv argument vector - strings pointed to, i don't really get it*/
        );
    }

    char Note[10];
    int KeyIndex = 0;
    FileIO::key CurrentKey;

    CurrentKey = fileioX.RetrieveKey(KeyIndex);

    for (int x = 0; x < 10; x++)
    {
        Note[x] = CurrentKey.Note[x];
    }

    //  There's a bunch of simple if statements here, nothing I need to bore you with
}

MidiOutput.h:

#pragma once

class MidiOutput {

public:

void FindDevice(int, char);
void PlayNote(unsigned char);
void EndNote();
void CloseDevice();

protected:

};

MidiOutput.cpp:

#include "MidiOutput.h"
#include <Windows.h>
#include <mmsystem.h>
#include <stdio.h>

union { unsigned long word; unsigned char data[4]; } message;
int midiport;
HMIDIOUT device;

void FindDevice(int argc, char** argv)
{

    if (argc < 2) {
        midiport = 0;
    } else {
        midiport = atoi(argv[1]);
    }
    printf("Midi output port set to %d.\n", midiport);

    midiOutOpen(&device, midiport, 0, 0, CALLBACK_NULL);

    message.data[0] = 0x90; //command byte
    message.data[1] = 60; //middle C 
    message.data[2] = 0; //volume, 0-100
    message.data[3] = 0; //not used
}

void MidiOutput::PlayNote(unsigned char Note)
{
    message.data[1] = Note;
    message.data[2] = 100;
}

void MidiOutput::EndNote()
{
    message.data[2] = 0;
}

void MidiOutput::CloseDevice()
{
    midiOutReset(device);
    midiOutClose(device);
}

确切的错误:

  

错误1错误LNK2019:未解析的外部符号“public:void __thiscall MidiOutput :: FindDevice(int,char)”(?FindDevice @ MidiOutput @@ QAEXHD @ Z)在函数“public:void __thiscall eventLoop :: FindFinalNote”中引用bool,bool,bool,bool,bool,bool,bool,bool)“(?FindFinalNote @ eventLoop @@ QAEX_N0000000 @ Z)C:\ Users \ Hilly \ documents \ visual studio 2010 \ Projects \ GHX \ GHX \ eventLoop.obj GHX

     

错误2错误LNK2019:未解析的外部符号_ imp _midiOutOpen @ 20在函数“void __cdecl FindDevice(int,char * *)”中引用(?FindDevice @@ YAXHPAPAD @ Z)C:\用户\ Hilly \ documents \ visual studio 2010 \ Projects \ GHX \ GHX \ MidiOutput.obj GHX

     

错误3错误LNK2019:函数“public:void __thiscall MidiOutput :: CloseDevice(void)”中引用了未解析的外部符号_ imp _midiOutClose @ 4(?CloseDevice @ MidiOutput @@ QAEXXZ)C: \ Users \ Hilly \ documents \ visual studio 2010 \ Projects \ GHX \ GHX \ MidiOutput.obj GHX

     

错误4错误LNK2019:函数“public:void __thiscall MidiOutput :: CloseDevice(void)”中引用了未解析的外部符号_ imp _midiOutReset @ 4(?CloseDevice @ MidiOutput @@ QAEXXZ)C: \ Users \ Hilly \ documents \ visual studio 2010 \ Projects \ GHX \ GHX \ MidiOutput.obj GHX

     

错误5错误LNK1120:4个未解析的外部C:\ Users \ Hilly \ documents \ visual studio 2010 \ Projects \ GHX \ Debug \ GHX.exe GHX

提前致谢,对代码墙感到抱歉,我不确定有什么必要。

1 个答案:

答案 0 :(得分:0)

缺少的符号midiOutOpenmidiOutClose等在DLL Winmm.dll中定义。您需要通过将其指定为链接命令的输入或将其包含在您的文件中来链接到Winmm.lib

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

您还收到有关MidiOutput::FindDevice的错误消息。您需要修复签名,以便.h文件和.cpp匹配,并使用类名(.cpp)限定MidiOutput::文件中的函数定义。