How can I avoid the LNK2005 linker error for variables defined in a header file?

后端 未结 7 1397
情话喂你
情话喂你 2020-12-19 09:28

I have 3 cpp files that look like this

#include \"Variables.h\"
void AppMain() {
    //Stuff...
}

They all use the same variables inside th

相关标签:
7条回答
  • 2020-12-19 10:14

    I had this error too although I work with extern definitions. The problem was initializing the variables in the extern definitions too:

    ID3D11VertexShader*         g_pVertexShader = nullptr;
    ...
    extern ID3D11VertexShader*  g_pVertexShader = nullptr;  // here's the problem 
    

    => error

    ID3D11VertexShader*         g_pVertexShader = nullptr;
    ...
    extern ID3D11VertexShader*  g_pVertexShader;           // without initializing  
    

    => no error, problem solved

    0 讨论(0)
提交回复
热议问题