错误 LNK2001:无法解析的外部符号 (C++)

编程入门 行业动态 更新时间:2024-10-10 07:32:32
本文介绍了错误 LNK2001:无法解析的外部符号 (C++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

假设我在一个名为 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 15:52:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157113.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!