在C++解决方案中重用基类时,MSVC链接器错误LNK2019
MSVC linker error LNK2019 when reusing a base class in C++ solution
这真的让我大吃一惊,Visual Studio 2008是如此的无脑,以至于它对以下错误毫无帮助。
我的C++解决方案中有几个项目。其中一个项目在crashreporter.h和crashreporter.cpp文件中有基本的C++类CCrashReporter。
我需要从它派生另一个类,该类位于同一解决方案中的另一个项目中。所以我做了:
//From CrashReporter2.h
#pragma once
#include "..BaseModulesCrashReporter.h"
class CCrashReporter2 :
public CCrashReporter
{
public:
CCrashReporter2(void);
virtual ~CCrashReporter2(void);
};
然后:
//From crashreporter2.cpp
#include "StdAfx.h"
#include "CrashReporter2.h"
CCrashReporter2::CCrashReporter2(void):
CCrashReporter(ENTERY_PARAM_FOR_REPORTER2)
{
}
CCrashReporter2::~CCrashReporter2(void)
{
}
上面的代码编译得还可以,但当链接器运行时,我会得到以下代码:
1>CrashReporter2.obj : error LNK2019: unresolved external symbol "public: __thiscall CCrashReporter::CCrashReporter(int) blah-blah
1>CrashReporter2.obj : error LNK2019: unresolved external symbol "public: __thiscall CCrashReporter::~CCrashReporter(void) blah-blah
1>C:UsersDevC++ProjName123DebugMod123.exe : fatal error LNK1120: 2 unresolved externals
请参阅Bo Persson的评论。每个项目都需要以这样或那样的方式链接到正确的文件。将源文件直接添加到项目中,或者创建一个链接到应用程序的静态/动态库项目。
相关文章:
- 我似乎无法让 msvc 链接器在 vscode 上正常工作
- MSVC 编译器/链接器何时合成标量/矢量删除析构函数
- Godbolt 在 MSVC 上包含 Windows.h 时无法链接?
- 静态链接MSVC库,动态链接Qt
- 使用 python3 为 msvc 构建 boost python - 链接器错误
- 使用 msvc /MDd cryptlib.lib 构建 Crypto++ 链接时找不到 cryptopp.lib
- 当将QT创建者与CMAKE一起使用时,为什么我不必手动链接MSVC库
- 链接错误时,使用CLION/CMAKE/MSVC 2015编译WIN32应用程序
- 在包含新CPP文件后的链接过程中,MSVC 错误
- 无法在 QT Creator/MSVC 中与 libtiff 链接
- 如何强制MSVC链接一个未使用的静态库(相当于GC——整个归档参数)
- 如何阅读MSVC C++链接错误
- 使用Windows函数SendMessage会导致与MSVC发生链接错误,但与MinGW不发生链接错误
- 在C++解决方案中重用基类时,MSVC链接器错误LNK2019
- 在窗口上使用 clang 链接 msvc 内部函数时出现问题
- 如何在 MSVC 中静态链接库
- 使用 MSVC 在 Win32 上构建 QtWebKit 时出错的链接器
- MSVC 是否错误地处理了类范围的静态与整数常量初始值设定项的链接
- 如何链接ENet和MSVC
- msvc++链接器错误,我不太理解