What could cause linking errors with global variables in header and cpp file?

50 Views Asked by At

#update: I am letting everyone know that I found out the issue. The file was somehow not included even though the IDE was telling me it was!? Thank you everyone!

I have a cpp file defining some global variables and a header file declaring them(using extern). For some reason I get linking errors when trying to use them. I have no idea what it could be. The header file:

#pragma once

#include <glm/glm.hpp>
#include "Camera.h"

extern int G_width;
extern int G_height;
extern Camera G_cam;

extern glm::mat4 G_model;
extern glm::mat4 G_view;
extern glm::mat4 G_proj;

and the cpp file:

#include "globals.h"

int G_width{ 800 };
int G_height{ 600 };
Camera G_cam{ glm::vec3{0,0,5} };

glm::mat4 G_model{ 1.0f };
glm::mat4 G_view{ G_cam.getView()};
glm::mat4 G_proj{ G_cam.getProj()};

The width and height used to work before, now they are unresolved symbols for main...

Adding more information asked in comments: I am using visual studio 2022 and the linking errors are LNK2001 unresolved external symbol, one for each variable that is used.

What should I do?

0

There are 0 best solutions below