2012-07-11 229 views
0

我在Visual Studio中有一個解決方案,它有2個項目,即PAL_TEST和Unit_Test。
我有PAL_TEST類,CPALResponse.h無法解決錯誤LNK2019:無法解析的外部符號

#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)" ([email protected]@@[email protected]) 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) 

目前還不清楚我的消息意味着什麼和如何解決錯誤

+0

@EitanT沒有幫助 – 2012-07-11 10:05:10

+0

這三個文件位於哪裏? – 2012-07-11 10:11:24

回答

0

下面是通常的清單,你的問題是其中之一:

  • 你不和導出類declspec(dllexport)也不在declspec(dllimport)的調用項目中導入它們。

  • 確保您使用實現來編譯文件。

  • 確保使用該類的項目與第一個項目生成的.lib相鏈接。

+0

抱歉,我是使用visual studio或製作windows庫的新手。如果你不能詳細解釋,這將是有益的 – 2012-07-11 09:56:57

+0

@AnubhavAgarwal谷歌搜索任何這些條款將幫助你更多。一切都應該詳細解釋。 – 2012-07-11 09:59:52

相關問題