无法解决错误 LNK2019:无法解析的外部符号 [英] Unable to resolve error LNK2019: unresolved external symbol

查看:109
本文介绍了无法解决错误 LNK2019:无法解析的外部符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 中有一个解决方案,它有 2 个项目,即 PAL_TEST 和 Unit_Test.
我在 PAL_TEST 中有一个类,CPALResponse.h

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

PAL_TEST CPALResponse.cpp 中的另一个文件

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

Unit_Test中有一个文件Unit_Test.cpp,

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

当我构建 Unit_Test 项目时,它会显示

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

推荐答案

这是通常的清单,您的问题是其中之一:

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

  • 您没有使用 declspec(dllexport) 导出类,也没有使用 declspec(dllimport) 在调用项目中导入它们.

  • 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.

确保使用类链接到第一个项目生成的 .lib 的项目.

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

这篇关于无法解决错误 LNK2019:无法解析的外部符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆