title: Error with linker for a extern variable declared in a header file
body: <p>I have a header file a.h which is included in 2 .c files a.c and b.c</p>
  
  <p>a.h</p>
  
  <pre><code>#ifndef A_H_INCLUDE
  #define A_H_INCLUDE
  extern int g;
  void chk(int f);
  #endif
  </code></pre>
  
  <p>a.c</p>
  
  <pre><code># include &lt;stdio.h&gt;
  # include "a.h"
  
  void chk(int f)
  {
      if(g==1) printf("\n CORRECT\n");
      else printf("\n INcorrect::%d: \n",f);
  }   
  </code></pre>
  
  <p>b.c</p>
  
  <pre><code># include &lt;stdio.h&gt;
  # include "a.h"
  
  int main()
  {
    int g;
    printf("\n ENTER::");
    scanf("%d",&amp;g);
    chk(56);
    return 0;
  }
  </code></pre>
  
  <p>On compiling the code it is giving me error</p>
  
  <pre><code>gcc a.c b.c a.h -o j
  /tmp/ccEerIPj.o: In function `chk':
  a.c:(.text+0x7): undefined reference to `g'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>I have already checked <a href="https://stackoverflow.com/questions/1164167/variable-declaration-in-a-header-file">Variable declaration in a header file</a> and i guess i am doing the same thing.</p>
  
  <p>Any suggestion or pointer to problem in code will be appreciated.</p>
  
  <p>Many thanks</p>