gpt4 book ai didi

c++ - 链接我的库时出现 LNK2005 已定义错误

转载 作者:行者123 更新时间:2023-11-28 04:11:05 24 4
gpt4 key购买 nike

<分区>

我创建了一个库,当我尝试在另一个项目中使用它时,出现了 LNK2005 错误。

结构.h

#pragma once
#ifndef STRUCTS_H
#define STRUCTS_H

#include <vector>
#include <string>

namespace Structs
{
struct GameObject
{
std::string name;

struct PosPoints
{
double px;
double py;
};

std::vector<PosPoints> Points;

double centroid[2];
bool active;
bool init;
};
std::vector<GameObject> objects;
}

#endif

结构.cpp

#include "stdafx.h"
#include "Structs.h"

struct Structs::GameObject gameObject;
std::vector<Structs::GameObject> objects;

核心函数.cpp

#include "stdafx.h"
#include "CoreFuncs.h"
#include "Structs.h"
#include <GLFW/glfw3.h>

//render
extern struct Structs::GameObject gameObject;
void RenderShapes()
{
for (int i = 0; i < Structs::objects.size(); i++)
{
for (int j = 0; j < Structs::objects[i].Points.size()-1; j++)
{
glBegin(GL_LINES);
glVertex3f(Structs::objects[i].Points[j].px, Structs::objects[i].Points[j].py, 0);
glVertex3f(Structs::objects[i].Points[j + 1].px, Structs::objects[i].Points[j + 1].py, 0);

glVertex3f(0.1, 0.1, 0);
glVertex3f(0.9, 0.9, 0);

glEnd();
}
}
}

image

当我在 CoreFuncs.cpp 中注释掉 #include "Structs.h" 时,问题就停止了,所以我假设 inlcude 是导致问题的原因。我环顾四周,发现许多使用 extern 的来源,但我似乎无法让它在这里工作。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com