title: How to use a object extern method in a main in C?
body: <p>I'm trying to do a simple "Oriented object" programm in C and I come from Java. I did some research and reading online and I came with this code :<br>
  <em>Declaring my base class</em></p>
  
  <pre><code>#ifndef FIGURE_H
  #define FIGURE_H
  struct figure{
      int(*m_draw) (struct figure* oref);
      int(*m_move) (struct figure* oref, int x, int y);
      int(*m_resize) (struct figure* oref, int x, int y);
      int(*m_rotate) (struct figure* oref, int angle);
      int(*m_erase) (struct figure* oref);
      int(*m_show) (struct figure* oref);
  
  };
  extern void init_figure(struct figure* oref);
  
  extern int draw (struct figure* oref);
  //... so on
  
  #endif //FIGURE
  </code></pre>
  
  <p>So this is the header file of my main structure called <code>Figure</code> I'm not really sure about the last part where I define all method extern I think it's wrong. Then I want to do a <code>figure_x</code> so I a <code>figure_x.c</code> I did the following code to redefine the methods<br>
  <em>figure_x.c</em>  </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "figure.h"
  
  int f_draw(struct  figure* oref){
      printf("Hey I'm an awesome figure (%p), I bet you never have seen something like that b4", oref);
      //idk what to do but when I tried with void I had error and with int it's fine lol help me
      return -1;
  }
  
  int f_move(int x, int y, struct  figure* oref){
      return -1;
  }
  
  //so on for each method defined in the figure structure
  void init_figure (struct figure* oref)
  {
      oref-&gt;m_draw = f_draw;
      oref-&gt;m_move = f_move;
      oref-&gt;m_resize = f_resize;
      oref-&gt;m_rotate = f_rotate;
      oref-&gt;m_erase  = f_erase;
      oref-&gt;m_show   = f_show;
  }
  </code></pre>
  
  <p>And finally I create a <code>main.c</code> where I chose to use a static declaration and usage of my objet like this:<br>
  <em>main.c</em>  </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "figure.h"
  int main() {
      //create a fig
      struct figure fig;
      //init the fig
      init_figure(&amp;fig);
      fig.m_draw(&amp;fig);
      fig.m_move(&amp;fig, 1, 2);
      fig.m_resize(&amp;fig, 3, 4);
      fig.m_rotate(&amp;fig, 5);
      fig.m_erase(&amp;fig);
      fig.m_show(&amp;fig);
      return 0;
  }
  </code></pre>
  
  <p>Now I get the following error : </p>
  
  <pre><code>C:\Users\xyz\AppData\Local\Temp\ccSxcgqa.o:main.c:(.text+0x15): undefined reference to `init_figure'
  collect2.exe: error: ld returned 1 exit status
  </code></pre>
  
  <p>My question is how can be <code>init_figure</code> undefined even if I use the key word <code>extern</code></p>