My settings file is creating LNK2001 errors

25 views Asked by At

newbie here! I recently started doing a small project in C++ but as soon as I try to compile it, I get a LNK2001 error due to my global variables file.

namespace {
    namespace Vars {
        extern int x;
        }
    }

As you can see I already tried fixing the error with an 'anonymous namespace' - a solution I found while googling the error, but it seems that none of the posts I saw so far are relatable to the error I'm getting.

In the .cpp the variables.h is included within, I get LNK2001 errors, but the other .cpp that has it included but not using it in any way does not.

The other .cpp would look like this:

#include "Variables.h"
#include "otherstuff.h"

void main(){
    if (Vars::x == 1){
        Stuff::OtherStuff->Run();
    }
}

The exact error given to me by the linker is:

error LNK2001: unresolved external symbol "int `anonymous namespace'::Vars::x" (?x@Vars@?A0x6c0990fe@@3HA)

Please feel free to criticize me, I'm new to C++ in general.

0

There are 0 answers