visual main.obj:错误LNK2019:C++中未解析的外部符号
visual main.obj : error LNK2019: unresolved external symbol in C++
我知道这个特定的错误已经被提了十几次了。然而,在我的所有搜索中,我都未能找到与我的具体情况相关的解决方案。
我是一名从Java学习C++的大学生。我知道使用矢量而不是数组会更好。我也知道我可能理解错了,我希望你的解释能在这方面对我有所帮助。
好的,这是我的三个文件:
main.cpp
#include <iostream>
#include "Arrays.h"
// Global variables
const int ARRAY_SIZE = 4;
const int MIN_RANGE = 0;
const int MAX_RANGE = 100;
// Main function
int main()
{
// Create two arrays populated with random numbers
int* Array1 = createArray(ARRAY_SIZE, MIN_RANGE, MAX_RANGE); // One of these days I'll understand why ponters are so cool
int* Array2 = createArray(ARRAY_SIZE, MIN_RANGE, MAX_RANGE); // Right now I find them a tad irritating
// Create the third array
int* Array3 = mergeArrays(Array1, Array2);
// Print all arrays with the format "array1[1] + array2[1] = array3[1]"
for (size_t i = 0; i < ARRAY_SIZE; i++)
{
std::cout << Array1[i] << " + " << Array2[i] << " = " << Array3[i] << std::endl << std::endl;
}
// Wait for input...
system("pause");
return 0;
}
Arrays.h
// Fucntion Prototypes
int* createArray(int arraySize, int minRange, int maxRange); // Creates an array populated with random numbers
int* mergeArrays(int* firstArray, int* secondArray); // Creates an array by adding the associated eements of two arrays
void printHeader(); // Prints the program's header
Arrays.cpp
#include <cstdlib>
#include <ctime>
#include "Arrays.h"
// Function to create an array with n random numbers between 0 and x
int* createArray(int arraySize, int minRange, int maxRange)
{
srand(time(NULL)); // Generate seed for rand()
int* Array = new int[arraySize]; // Create a pointer to a new array
for (size_t i = 0; i < arraySize; i++) // Loop to assign values to each index in the array
{
// Generate a random number for each index in the array
Array[i] = (rand() % maxRange) + minRange;
}
return Array;
}
// Function to create an array from two arrays with the associated values added together
int* mergeArrays(int* firstArray, int* secondArray, int arraySize)
{
int* resultArray = new int[arraySize]; // Create a pointer to a new array
for (size_t i = 0; i < arraySize; i++) // Loop to assign values to each index in the array
{
/* The value at each index in the array is equal to the sum of the values
at the same index in the other two arrays*/
resultArray[i] = firstArray[i] + secondArray[i];
}
return resultArray;
}
当我在Visual Studio 2013中构建它时,我得到的错误是:
1>main.obj : error LNK2019: unresolved external symbol "int * __cdecl mergeArrays(int *,int *)" (?mergeArrays@@YAPAHPAH0@Z) referenced in function _main
1>C:Assignment 2_1DebugAssignment 2_1.exe : fatal error LNK1120: 1 unresolved externals
声明和实现之间存在差异。
int* mergeArrays(int* firstArray, int* secondArray) //.h
int* mergeArrays(int* firstArray, int* secondArray, int arraySize) //.cpp
您的主函数使用了.h文件中的函数,但是,这个函数从未实现。在cpp文件中,您声明了一个具有相同名称但另一个签名(重载)的函数
相关文章:
- 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