LNK2019错误c++未解析的外部符号
LNK2019 error c++ unresolved external symbol
我得到了这些错误信息:
错误1错误LNK2019: unresolved外部符号"public: void"__thiscall ArrayIntStorage: sortOwn(空白)"(? sortOwn@ArrayIntStorage@@QAEXXZ)函数引用_main G: 08227 主要联队 08227 _acw2_test_harnesses_2010-11 C_Style_Array 主要。obj C_Style_Array
错误2错误LNK2019: unresolved外部符号"public: void"__thiscall ArrayIntStorage: sortStd(空白)"(? sortStd@ArrayIntStorage@@QAEXXZ)函数引用_main G: 08227 主要联队 08227 _acw2_test_harnesses_2010-11 C_Style_Array 主要。obj C_Style_Array
错误3错误LNK2019: unresolved外部符号"类Std::basic_ostream> &__cdecloperator<& lt;(类Std::basic_ostream> &ArrayIntStorage &)(? ? 6 @yaaav basic_ostream@DU美元? char_traits@D@std@@@std@@AAV01@ABVArrayIntStorage@@@Z美元)函数引用_main G: 08227 主要联队 08227 _acw2_test_harnesses_2010-11 C_Style_Array 主要。obj C_Style_Array
错误4错误LNK2019: unresolved外部符号"类Std::basic_istream> &__cdecl操作符>>(类Std::basic_istream> &ArrayIntStorage,)"(? ? 5 @yaaav basic_istream@DU美元? char_traits@D@std@@@std@@AAV01@AAVArrayIntStorage@@@Z美元)函数引用_main G: 08227 主要联队 08227 _acw2_test_harnesses_2010-11 C_Style_Array 主要。obj C_Style_Array
错误5错误LNK2019: unresolved外部符号"public":bool__thiscall ArrayIntStorage: setReadSort (bool)"(? setReadSort@ArrayIntStorage@@QAE_N_N@Z)函数引用_main G: 08227 主要联队 08227 _acw2_test_harnesses_2010-11 C_Style_Array 主要。obj C_Style_Array
错误6错误LNK1120: 5 unresolved外部G: 8227ACWMAIN 8227_ACW2_Test_Harnesses_2010-11C_Style_ArrayDebugC_Style_Array.exe 11 C_Style_Array
我不知道发生了什么,我想知道我是否错过了什么?我是新手,它没有给我任何行号,所以我不确定给你哪个代码,所以我给你这部分
#include <fstream>
#include <iostream>
using namespace std;
#include "ArrayIntStorage.h"
int main(int argc, char **argv) {
ifstream fin1("ACW2_data.txt");
ofstream out1("1-arrayUnsortedRead.txt");
ofstream out2("2-arrayUnsortedRead-thenSTDSort.txt");
if(!fin1.is_open())
{
cout << "FAIL" << endl;
return 1;
}
ArrayIntStorage arrayStorage1;
arrayStorage1.setReadSort(false); // do not read sort
// read in int values into data structure
fin1 >> arrayStorage1;
// output int values in data structure to file
out1 << arrayStorage1;
// sort data structure using std
arrayStorage1.sortStd();
// output int values in data structure to file
out2 << arrayStorage1;
fin1.close();
out1.close();
out2.close();
您的链接器(编译器的一部分)找不到ArrayIntStorage::sortOwn()
的定义位置
这通常发生:
-
ArrayIntStorage::sortOwn()
的定义在另一个。c文件中,你忘了告诉编译器(所以没有编译), - ArrayIntStorage是一个头唯一的库(所以没有其他。c文件),在这种情况下,你可能已经忘记实现函数
sortOwn()
,并只声明它。 - ArrayIntStorage是一个没有被链接的外部库。(如Tomalak Geretkal所述,并通过遵循paxdiablo设置的步骤来解决)
如果这两者都不是,或者你发现这些选项令人困惑,请发布头文件ArrayIntStorage.h
和相应的。c文件(如果有一个)。
这是一个链接器错误,一旦你了解了这个过程,就可以很容易地解决。
通过#include
-ing在你的源代码的头文件,让编译器知道它需要的定义。
但是,还需要一个额外的步骤。你必须把所有不同的目标文件和库链接在一起。
这是因为,虽然标题包含有关ArrayIntStorage
的信息,但它的实际代码在其他地方。这是在链接阶段购买的。
基本上,您需要确保目标文件或库包含在您的构建过程中。
例如,下面的gcc
命令将包含abc。从libxyz.a
存档库中引入所需的任何内容:
gcc -o myprog myprog.c abc.o -L/path/to/libs -lxyz
对于不同的环境,也可能有不同的处理方法。例如,IDE很可能将它放在某种类型的项目设置中。
这个答案提供了许多环境中常见的编译和链接过程的更多信息。
您忘了链接定义ArrayIntStorage函数的库。请阅读该库的文档,以了解如何在项目中使用它。
看起来ArrayIntStorage被编译成一个库。检查项目的链接器详细信息,并添加库。
可能与这个问题中的代码无关,但是如果您忘记在库中导出函数声明,然后尝试从该库外部使用该函数,也会得到此错误。例如,以下代码
bool operator==(const Foo &a, const Foo &b);
应该成为
MY_EXPORT_MACRO bool operator==(const Foo &a, const Foo &b);
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 未解析的外部符号_MsiLocateComponentW@12.
- 在C++中使用 gRPC 时未解析的外部符号
- LibPrivoxy: 未解析的外部符号 __declspec(dllimport) int __stdcall Sta
- 尝试从 XamlApplication 编译 C++/WinRT 空白应用程序时,我收到未解析的外部符号 winrt_make_*
- 我收到错误LNK2001:未解析的外部符号(C++代码)
- 可视抽象类 c++(错误 LNK 2001:未解析的外部符号)
- 如何摆脱C++中未解析的外部符号"private: static char"错误?
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 仅在少数方法(静态或共享库)中解析的外部符号
- 未解析的外部符号"__declspec(dllimport)与 Spdlog c++ 库
- 函数 _main (OPENGL C++) 中引用的未解析的外部符号 ________
- 错误LNK2019未解析的外部符号"public: __thiscall SLinkList<char>::SLinkList<char>(void)"
- 使用静态 constexpr 成员的未解析外部符号
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- Dlib LNK2001未解析的外部符号USER_ERROR__consistent_build_configurati
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 链接器错误:切换到unicode生成给出:未解析的外部符号WinMain
- 类模板上一个特定函数的未解析外部符号
- LNK2001:未解析的外部符号public:static类std::vector