LNK2020 & 2020由于添加了包含相同类的其他项目,旧工作项目中的旧类中出现 LNK1120 错误
将我的解决方案从 1 个项目重构为 3 个项目后,我遇到了意外的链接器错误。在第一个实例中,我得到两个未解析的令牌,例如
错误 LNK2020:无法解析的令牌 (0600000C) Mynamespace.MyClass::unresolvedStaticFunc
错误 LNK2020:无法解析的令牌 (0600000C) Mynamespace.MyClass::unresolvedOtherStaticFunc
致命错误 LNK1120:2 个未解析的外部
我在重构中尚未触及此类。这两种方法都在标头中声明为静态,但在正文(cpp 文件)中未声明。
我重新检查了我的错误,新项目编译正常,但迫使旧项目在链接时中断。
我想我需要将文件添加到我的新项目中,但它们现在似乎很好地分成了自己的文件夹。也许是共享类的另一个项目?我添加了我认为简单的功能,我的项目数量已经增加了两倍。
I am getting unexpected linker errors after refactoring my solution from 1 to 3 projects. In this first instance I get two unresolved tokens, like
error LNK2020: unresolved token (0600000C) Mynamespace.MyClass::unresolvedStaticFunc
error LNK2020: unresolved token (0600000C) Mynamespace.MyClass::unresolvedOtherStaticFunc
fatal error LNK1120: 2 unresolved externals
I have not touched this class in my refactoring. Both methods are declared static in the header but not the body (cpp file).
I've rechecked my errors and the new project is compiling fine but forcing the old one to break on linking.
I think I need to add files to my new projects but they seem nicely separated into their own folders now. Another project for the shared class perhaps? I am adding what I thought a simple feature and my project count has already tripled.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该在多个项目中
#include
包含托管类型的头文件。相反,在新项目中,添加对旧项目的程序集引用;这样,类型信息将从嵌入到旧项目程序集中的 .NET 元数据中收集。You should not be
#include
ing header files containing managed types across multiple projects. Instead, in the new project, add an assembly reference to the old project; this way, the type information will be gathered from the .NET metadata embedded into the old project's assembly.