title: C extern struct pointer dynamic allocation
body: <p>I'm trying to allocate dynamically a global struct in c, but something makes my c file not being able to find the reference to the extern variable.</p>
  
  <p>The log:</p>
  
  <pre><code>main.c:18: undefined reference to `gate_array'
  </code></pre>
  
  <p>extern.h</p>
  
  <pre><code>#ifndef EXTERN_H_
  #define EXTERN_H_
  
  
  typedef struct gate_struct {
      int out;
  } gate;
  
  extern gate *gate_array;
  
  
  #endif /* EXTERN_H_ */
  </code></pre>
  
  <p>main.c:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  #include "extern.h"
  
  int main(int argc, char *argv[]){
  
      gate_array = (gate*) malloc (2* sizeof(gate));
  
      return 0;
  } 
  </code></pre>
  
  <p>Thanks!</p>