2012-07-11 225 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

相关问题