LNK1169:找到一个或多个多重定义的符号。
我的项目是一个并行化的随机数生成器,使用MPI和并行前缀算法。我查找了许多LNK1169错误的解决方案。为了防止这种情况,我将许多变量设为静态,我查找了多个定义的变量,并且找不到任何变量。我没有头文件,其中变量可以被多次定义。如果有人能帮我找到错误,我会非常感激。我很确定在某个地方的functions.cpp中发生了错误,因为在我尝试实现parallel_prefix函数之前,所有内容都正确构建。
这里也是LNK2005的输出:
LNK2005“class std :: vector>,class std :: allocator>>> __cdecl parallel_prefix(class std :: vector>,class std :: allocator>>>,class std: :allocator>,class std :: allocator>>>>>,int,int)“(?parallel_prefix @@ YA?AV?$ vector @ V?$ vector @ HV?$ allocator @ H @ STD @@@ STD @@ V'$分配器@ V'$矢量@ HV?$分配器3 H @ STD @@@ STD @@@ 2 @@ STD @@ V'$ @矢量V'$矢量@ V· $矢量@ HV?$分配器3 H @ STD @@@ STD @@ V'$分配器@ V'$矢量@ HV?$分配器3 H @ STD @@@ STD @@@ 2 @@ STD @@ V· $ @分配器V'$ @矢量V'$ @矢量HV?$ @分配器H + STD @@@性病@@ V'$ @分配器V'$ @矢量HV?$ @分配器H + STD @@@ STD @ @@ 2 @@ std @@@ 2 @@ 2 @HH @ Z)已经在functions.obj中定义了RandomNumberGenerator
这是我的代码。
RandomNumberGenerator.cpp
false
functions.cpp
#include "functions.cpp"
int main(int argc, char *argv[])
{
// Establishes what rank it is, and how many processes are running.
static int rank, p, n, per_Process;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &p);
static vector<int> Broadcast_data;
n = 100;
per_Process = n / p;
// The first and second arguments are constants for number generation, the third is a large prime to mod by, and the fourth is a random seed. x1 is calculated based off x0.
// All provided by the user except x1.
// Rank 0 broadcasts the data to all processes.
if (rank == 0)
{
for (static int i = 1; i < 5; i++)
{
Broadcast_data.push_back(std::atoi(argv[i]));
}
Broadcast_data.push_back(std::atoi(argv[1]) *std::atoi(argv[4]) % std::atoi(argv[3]));
// NOTE: THIS PUSH BACK IS HOW MANY RANDOM NUMBERS WILL BE GENERATED
Broadcast_data.push_back(n);
cout << "Rank " << rank << " Broadcast Data: ";
for (static int i = 0; i < 6; i++)
{
cout << Broadcast_data[i] << " ";
}
cout << endl;
}
else
{
Broadcast_data.resize(6);
}
MPI_Bcast(Broadcast_data.data(), 6, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
// Initialize an array of n/p values at every process. Each of the n/p values is the matrix M.
// M is this 2 dimmensional array:
// [ a 1 ]
// [ b 0 ]
static vector<vector<int>> M;
M.resize(2);
M[0].resize(2);
M[1].resize(2);
M[0][0] = Broadcast_data[0];
M[0][1] = Broadcast_data[1];
M[1][0] = 1;
M[1][1] = 0;
// Now we must initialize the array of these M values. Notation might get complex here
// as we are dealing with 3D arrays.
static vector<vector<vector<int>>> M_values;
M_values.resize(per_Process);
for (static int i = 0; i < per_Process; i++)
{
M_values.push_back(M);
}
// Now we are ready for the parallel prefix operation. Note that the operator here
// is matrix multiplication.
static vector<vector<int>> prefix;
prefix = parallel_prefix(M_values, rank, p);
MPI_Finalize();
return 0;
}
答案 0 :(得分:3)
您在functions.cpp
中包含main.cpp
,并且可能还将其包含在您的项目中。这会将functions.cpp
中的内容编译两次。
不要在主要内容中包含functions.cpp
。使用functions.h
来声明其中的函数。