【问题标题】:LNK2019 unresolved external symbol "public: __thiscallLNK2019 未解析的外部符号“public: __thiscall”
【发布时间】:2018-11-13 16:50:33
【问题描述】:

头文件 TCP.h

class CTCPcomm {
public:
    CTCPcomm(bool bOverLapped = false, long lTimeOut = 0);
    ~CTCPcomm(void);

TCP.cpp 类

CTCPcomm::CTCPcomm ( bool bOverLapped, long lTimeout ) {
.......
}
CTCPcomm::~CTCPcomm ( void ) {
.......
}

这是为 plc_test.cpp 调用的

int main(){
CTCPcomm    m_TCPcon(true, lTimeout);
.......
}

这给了我错误,

Severity    Code    Description Project File    Line    Suppression State Error LNK2019 unresolved external symbol "public: __thiscall CTCPcomm::CTCPcomm(bool,long)" (??0CTCPcomm@@QAE@_NJ@Z) referenced in function "void __cdecl `dynamic initializer for 'm_TCPcon''(void)" (?? __Em_TCPcon@@YAXXZ) plc_test
Severity    Code    Description Project File    Line    Suppression State Error LNK2019 unresolved external symbol "public: __thiscall CTCPcomm::~CTCPcomm(void)" (??1CTCPcomm@@QAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'm_TCPcon''(void)" (??__Fm_TCPcon@@YAXXZ) plc_test

我使用 Visual Studio 2015,并将其编译为 .exe 文件。 我已经阅读了很多帖子,但他们说将执行类型更改为 .lib 但我希望这个项目是一个可执行文件,所以我想坚持使用 .exe 如果编译为 .lib 而不是 .exe,为什么它编译时没有错误? 如果我想将它作为.exe执行而没有错误应该怎么做?

【问题讨论】:

  • 你的项目中真的有 TCP.cpp 吗?
  • 是的。这是我项目的一部分

标签: c++ visual-c++ visual-studio-2015


【解决方案1】:

我将上面的代码放在 Visual Studio 2015 项目中,它在 x86 和 x64 中都可以正常工作(编译为 exe)。

你还在做什么?除了您展示的内容之外,您只需要:
#include "TCPcomm.h" //after #include "stdafx.h"

long lTimeout = 10; //在主目录中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    • 2012-12-19
    • 2015-05-28
    • 2014-11-07
    • 2013-06-01
    • 1970-01-01
    • 2014-05-27
    相关资源
    最近更新 更多