I've made a library when i try and use it in another project i get a LNK2005 error.
Structs.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
Structs.cpp
#include "stdafx.h"
#include "Structs.h"
struct Structs::GameObject gameObject;
std::vector<Structs::GameObject> objects;
CoreFuncs.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();
}
}
}
The issue stops happening when i comment out the #include "Structs.h"
in CoreFuncs.cpp
So I assume that inlcude is what is causing the issues. I have looked around and found many sources using extern
but i cant seem to get it working here.