0

私は Visual Studio にソリューションを持っています。PAL_TEST と Unit_Test という 2 つのプロジェクトがあります。
私は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;
};

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;
}

Unit_Test にはファイル Unit_Test.cpp があり、

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

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

Unit_Test プロジェクトをビルドすると、それが表示されます

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)

メッセージの意味とエラーの解決方法がわかりません

4

1 に答える 1

0

これが通常のチェックリストです。問題は次のいずれかです。

  • を使用してクラスをエクスポートしdeclspec(dllexport)たり、呼び出し元のプロジェクトにインポートしたりしていませんdeclspec(dllimport)

  • 必ず実装を使用してファイルをコンパイルしてください。

  • クラスを使用するプロジェクトが.lib、最初のプロジェクトによって生成された に対してリンクされていることを確認してください。

于 2012-07-11T09:53:28.670 に答える