title: Error: Unresolved external symbol error in C++
body: <p>The compilation issue is caused by the global variable [ <code>All_Sockets</code> ], here is the minimal example</p>
  <p>main.cpp</p>
  <pre><code>#include &lt;winsock2.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;vector&gt;
  #include &quot;global.h&quot;
  
  
  int main() {
  
      std::vector&lt;SOCKET&gt; All_Sockets(10, INVALID_SOCKET);    // definition of global var
  
      getchar();
      return 1;
  }
  </code></pre>
  <p>global.h</p>
  <pre><code>#pragma once
  #include &lt;vector&gt;
  #include &lt;Windows.h&gt;
  
  extern std::vector&lt;SOCKET&gt; All_Sockets;      // declaration of global variable
  </code></pre>
  <p>file1.cpp</p>
  <pre><code>#include &quot;global.h&quot;
  #include &lt;windows.h&gt;
  
  void ftn1(){
      int i = 2;
      SOCKET Client_socket = All_Sockets[i];      // usage of global var
  }
  </code></pre>
  <p>I'm building this project in visual studio and the following linking error occurs</p>
  <pre><code>1&gt;file1.obj : error LNK2001: unresolved external symbol &quot;class std::vector&lt;unsigned int,class std::allocator&lt;unsigned int&gt; &gt; All_Sockets&quot;
  </code></pre>