c++ - 错误 LNK2019 : unresolved external symbol

标签 c++ visual-studio visual-studio-2008 lnk2019

好的,所以我在尝试找出代码中的问题时遇到了问题。我有很多代码,所以我只会发布编译时出现问题的相关部分。我在一个类中有以下函数,它会编译并且一切都会正常运行,直到我调用函数“CalculateProbabilityResults”并在其中运行第 7 行代码。我已经在我的程序中“取消注释”了这行代码,这样您就可以更容易地找到它。我很确定我有正确的 #include 指令,因为它在不调用函数时编译得很好,所以这不是问题,不是吗?我知道我的一些命名符号需要一点帮助,所以请多多包涵。在此先感谢您的帮助。

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 方法:

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

但是你把它定义为一个自由函数:

int getTimeFrameFile(int timeInHours, int timeFrameSize) {

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

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

关于c++ - 错误 LNK2019 : unresolved external symbol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2122397/

相关文章:

c++ - 重新开始循环 C++

c++ - 将命令从 C++ 程序传递到终端的问题

c++ - 将位数组转换为短

ASP.NET 和 Web Tools 2012.2 引用 LESS 文件

visual-studio - 在visual studio中打开的文件名旁边的数字是多少?

visual-studio - 将搜索限制为 Visual Studio 中的指定文件夹或文件类型?

c# - 如何在 Visual Studio 2008 中永久禁用区域折叠

c++ - Windows 7 中的 NUMA 内存区域分配

c++ - CMake "uuid"链接失败

c++ - VS 调试器中未正确显示具有嵌套类型的 QList