错误LNK2019:未解析的外部符号 [英] error LNK2019: unresolved external symbol

查看:224
本文介绍了错误LNK2019:未解析的外部符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我有一个问题,试图找出我的代码中的问题。我有很多代码,所以我只会发布相关的部分,当我编译时搞乱。我有一个类中的以下函数,它将编译,一切都将运行良好,直到我调用函数CalculateProbabilityResults,它运行其中的第7行代码。我已经在我的程序中解除注释这行代码,所以你可以找到它更容易。我很肯定我有正确的#include指令所需,因为它编译精细时,不调用函数,所以不能是问题可以吗?我知道我的一些命名记法需要一点帮助,所以请承担与我。感谢提前为帮助家伙。

Ok, so I'm having a problem trying figure out the problem in my code. I have a lot of code so I'm only going to post the relevant parts that are messing up when I compile. I have the following function inside of a class and it will compile and everything will run fine until I call the function "CalculateProbabilityResults" and it runs the 7th line of code within it. I've "de-commented" this line of code in my program so you can find it easier. I'm pretty sure I have the right #include directives needed since it compiles fine when not calling the function, so that can't be the problem can it? I know some of my naming notation needs a little help, so please bear with me. Thanks in advance for the help guys.

int SQLServer::CalculateProbabilityResults(int profile, int frame, int time_period, int TimeWindowSize) {
    ofstream ResultFile;
    stringstream searchFileName;
    stringstream outputName;
    vector<vector<int>> timeFrameItemsets;
    int num = getTimeFrameFile(frame*TimeWindowSize, TimeWindowSize);
    cout << num << endl;

    //outputName << "Results" << getTimeFrameFile((frame*TimeWindowSize), TimeWindowSize) << ".csv";
    cout << outputName.str() << endl;
    outputName.clear();
    //ResultFile.open(outputName.str().c_str());
    ResultFile.close();
    result.resize(0);
    return 0;
}

int getTimeFrameFile(int timeInHours, int timeFrameSize) {
    int fileNum = 0;
    int testWin;
    if (timeInHours > 24) {
        while (timeInHours >24)
            timeInHours -= 24;
    }
    for (testWin = 0; testWin < 24/timeFrameSize; testWin++) {
        if (timeInHours >= testWin*timeFrameSize && timeInHours < (testWin+1)*timeFrameSize)
            fileNum = testWin+1;
    }
    if (fileNum == 0)
        fileNum = testWin+1;
    return fileNum;
}

呼叫记录

1>------ Rebuild All started: Project: MobileSPADE_1.3, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'MobileSPADE_1.3', configuration 'Debug|Win32'
1>Compiling...
1>main.cpp
1>MobileSPADE.cpp
1>SQLServer.cpp
1>Generating Code...
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>LINK : C:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\Debug\MobileSPADE_1.3.exe not found or not built by the last incremental link; performing full link
1>SQLServer.obj : error LNK2019: unresolved external symbol "public: int __thiscall SQLServer::getTimeFrameFile(int,int)" (?getTimeFrameFile@SQLServer@@QAEHHH@Z) referenced in function "public: int __thiscall SQLServer::CalculateProbabilityResults(int,int,int,int)" (?CalculateProbabilityResults@SQLServer@@QAEHHHHH@Z)
1>C:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\Debug\MobileSPADE_1.3.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\MobileSPADE_1.3\Debug\BuildLog.htm"
1>MobileSPADE_1.3 - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


推荐答案

编译器认为getTimeFrameFile是一个SQLServer方法:

The compiler thinks that getTimeFrameFile is a SQLServer method:


未解析的外部符号public:int __thiscall SQLServer :: getTimeFrameFile(int,int)

unresolved external symbol "public: int __thiscall SQLServer::getTimeFrameFile(int,int)"

你定义为一个自由函数:

but you have it defined as a free function:

int getTimeFrameFile(int timeInHours, int timeFrameSize) {

将自由函数更改为类方法将会解决问题:

Change that from a free function to a class method will solve the problem:

int SQLServer::getTimeFrameFile(int timeInHours, int timeFrameSize)

这篇关于错误LNK2019:未解析的外部符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆