我最近从 2005 年升级到 2012 年(我很确定)并且在构建我的解决方案时遇到了链接错误。经过数小时的谷歌搜索和四处搜索后,我的想法已经耗尽。我已经建立了几十个项目,所以我很确定我做的一切都是正确的,但公平地说,已经有几年了。
因此,作为测试,我建立了一个新项目。我称它为 App,一个 Windows 应用程序 (.exe)。我创建了第二个名为 Core 的项目,并在其配置类型中将其标记为静态库 (.lib)。两者都是解决方案的一部分。在 Core 中,我添加了 Test.cpp 和 Test.h,其中包含一个小类,其中包含一个简单的功能。然后,在 Window 的应用程序 WinMain.cpp 文件中,我有 WinMain(),我通过 CTest 测试调用这个测试类;测试结果();
除此之外,我将项目 App 的 Project Dependencies 设置为 Core,并最终将 Test.cpp/.h 所在的 Core 代码的路径添加到 App 的 Additional Include Directories 中。
我收到以下链接错误,我终生无法弄清楚原因。有谁知道我可能错过了什么步骤或 2012 年与以前的版本相比有什么变化?非常感谢您的帮助!
1>------ Build started: Project: App, Configuration: Debug Win32 ------
1>WinMain.obj : error LNK2019: unresolved external symbol "public: __thiscall CTest::CTest(void)" (??0CTest@@QAE@XZ) referenced in function _WinMain@16
1>WinMain.obj : error LNK2019: unresolved external symbol "public: __thiscall CTest::~CTest(void)" (??1CTest@@QAE@XZ) referenced in function _WinMain@16
1>WinMain.obj : error LNK2019: unresolved external symbol "public: int __thiscall CTest::Result(void)" (?Result@CTest@@QAEHXZ) referenced in function _WinMain@16
1>D:\Work\Test_Linker_Stupidity\App\Debug\App.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ========