Unresolved external symbol in object files(目标文件中未解析的外部符号)
问题描述
在 Visual Studio 中编码期间,我遇到了一个未解决的外部符号错误我不知道该怎么办.我不知道怎么了.你能解密我吗?我应该在哪里寻找什么样的错误?
During coding in Visual Studio I got an unresolved external symbol error and I've got no idea what to do. I don't know what's wrong. Could you please decipher me? Where should I be looking for what kind of errors?
1>Form.obj : error LNK2019: unresolved external symbol "public: class Field * __thiscall Field::addField(class Field *)" (?addField@Field@@QAEPAV1@PAV1@@Z) referenced in function "public: void __thiscall Form::parse(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?parse@Form@@QAEXAAV?$basic_stringstream@DU?$char_traits@D@V?$allocator@D@@Z)
1>Form.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall Field::parse(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?parse@Field@@UAEXAAV?$basic_stringstream@DU?$char_traits@D@V?$allocator@D@@Z) referenced in function "public: __thiscall InputField::InputField(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (??0InputField@@QAE@AAV?$basic_stringstream@DU?$char_traits@D@V?$allocator@D@@Z)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Field::prompt(void)" (?prompt@Field@@UAEXXZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Field::getName(void)" (?getName@Field@@UAE?AV?$basic_string@DU?$char_traits@D@V?$allocator@D@XZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Field::getType(void)" (?getType@Field@@UAE?AV?$basic_string@DU?$char_traits@D@V?$allocator@D@XZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Field::describe(void)" (?describe@Field@@UAEXXZ)
1>C:Users omyDocumentsVisual Studio 2010Projectszapoctovkac++Debugzapoctovkac++.exe : fatal error LNK1120: 6 unresolved externals
推荐答案
这个错误通常意味着某些函数有声明,但没有定义.
This error often means that some function has a declaration, but not a definition.
示例:
// A.hpp
class A
{
public:
void myFunc(); // Function declaration
};
// A.cpp
// Function definition
void A::myFunc()
{
// do stuff
}
在您的情况下,无法找到定义.问题可能是您包含了一个头文件,它引入了一些函数声明,但您要么:
In your case, the definition cannot be found. The issue could be that you are including a header file, which brings in some function declarations, but you either:
- 不要在您的 cpp 文件中定义函数(如果您自己编写此代码)
- 不要包含包含定义的 lib/dll 文件
一个常见的错误是你将一个函数定义为一个独立的函数而忘记了类选择器,例如A::
,在你的 .cpp 文件中:
A common mistake is that you define a function as a standalone and forget the class selector, e.g. A::
, in your .cpp file:
错误: void myFunc() {/* do stuff *
本文标题为:目标文件中未解析的外部符号
基础教程推荐
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01