Unable to resolve error LNK2019: unresolved external symbol

百般思念 提交于 2019-12-11 18:48:48

问题


I have a solution in Visual Studio, it has 2 projects namely PAL_TEST and Unit_Test.
I have a class in PAL_TEST, CPALResponse.h

#include "CFW_Stl.h"

class CPALResponse
{
  public:
    void SetCommandSucceeded(bool bCommandSucceeded = false);
    bool GetCommandSucceeded();
    void SetCommandType(int nCommandType);
    int GetCommandType();

  private:
    bool m_bCommadSucceeded;
    int m_nCommandType;
};

another file in PAL_TEST CPALResponse.cpp

#include "stdafx.h"
#include "CFW_CPALResponse.h"

void CPALResponse::SetCommandSucceeded(bool bCommandSucceeded)
{
    m_bCommadSucceeded = bCommandSucceeded;
}
bool CPALResponse::GetCommandSucceeded()
{
    return m_bCommadSucceeded;
}
void CPALResponse::SetCommandType(int nCommandType)
{
    m_nCommandType = nCommandType;
}
int CPALResponse::GetCommandType()
{
    return m_nCommandType;
}

There is a file Unit_Test.cpp in Unit_Test,

#include "stdafx.h"
#include "../PAL_TEST/CFW_CPALResponse.h"

int _tmain(int argc, _TCHAR* argv[])
{
    CPALResponse a;
    a.SetCommandSucceeded(true);
    return 0;
}

When I build the Unit_Test project it shows me

1>------ Build started: Project: Unit_Test, Configuration: Debug Win32 ------
1>Linking...
1>Unit_Test.obj : error LNK2019: unresolved external symbol "public: void __thiscall CPALResponse::SetCommandSucceeded(bool)" (?SetCommandSucceeded@CPALResponse@@QAEX_N@Z) referenced in function _wmain
1>C:\Users\anubhav.a\Documents\Visual Studio 2008\Projects\PAL_TEST\Debug\Unit_Test.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\anubhav.a\Documents\Visual Studio 2008\Projects\PAL_TEST\Unit_Test\Debug\BuildLog.htm"
1>Unit_Test - 2 error(s), 0 warning(s)

It is unclear to me what the message means and how to resolve the error


回答1:


Here's the usual checklist, your problem is one of these:

  • You're not exporting the class with declspec(dllexport) nor importing them in the calling project with declspec(dllimport).

  • Make sure you compile the file with the implementations.

  • Make sure the project that uses the class links against the .lib generated by the first project.



来源:https://stackoverflow.com/questions/11429971/unable-to-resolve-error-lnk2019-unresolved-external-symbol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!