错误 LNK2001:无法解析的外部符号 (C++) [英] error LNK2001: unresolved external symbol (C++)

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

问题描述

假设我在一个名为 one.cpp 的文件中有一个名为 DoThis(const char *abc) 的函数.因此,当我尝试从不同源文件 (two.cpp) 中的另一个函数调用此函数时,出现错误:error LNK2001: unresolved external symbol (C++),即使我使用了 #include "one.h"我要解决这个问题吗?

Say I have this function called DoThis(const char *abc) in a file called one.cpp. So when I attempt to call this function from another function in a different source file (two.cpp), I get the error: error LNK2001: unresolved external symbol (C++), even though I used #include "one.h" What would I do to fix this?

推荐答案

这意味着你的函数定义不存在于你的程序中.您忘记将 one.cpp 添加到您的程序中.

That means that the definition of your function is not present in your program. You forgot to add that one.cpp to your program.

在这种情况下,要添加"的含义取决于您的构建环境及其术语.在 MSVC 中(因为您显然使用 MSVC),您必须将 one.cpp 添加到项目中.

What "to add" means in this case depends on your build environment and its terminology. In MSVC (since you are apparently use MSVC) you'd have to add one.cpp to the project.

从更实际的角度来说,适用于所有典型的构建方法,当您链接程序时,从 one.cpp 创建的目标文件丢失了.

In more practical terms, applicable to all typical build methodologies, when you link you program, the object file created form one.cpp is missing.

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

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