I have a set of global variables and a method in a cpp file.
int a;
int b;
int c;
void DoStuff()
{
}
in the header file I have declared them explicitly with the extern keyword. My problem is when I include the header file in another C++ file, I can’t use the external variables and the method. It’s giving a linker error saying error LNK2001: unresolved external symbol for the methods and variables. What have I done wrong here??
PS: DoStuff() method populates the variables. All the header files and cpp files are in the same project folder.
Thank You!
Try this
Define those variables inside your header instead of just declaring them.
extern int x;is just a declaration(not a definition)Simple example
a.cppb.cpp