title: Undefined Reference to a function
body: <p>I'm using Linux and I have the following files:</p>
  
  <pre><code>main.c, main.h
  fileA.c, fileA.h
  fileB.cpp, fileB.h
  </code></pre>
  
  <p>The function <code>F1()</code> is declared in <code>fileB.h</code> and defined in <code>fileB.cpp</code>. I need to use the function in <code>fileA.c</code>, and so I declared the function as </p>
  
  <pre><code>extern void F1();
  </code></pre>
  
  <p>in <code>fileA.c</code>.</p>
  
  <p>However, during compilation, I got the error </p>
  
  <pre><code>fileA.c: (.text+0x2b7): undefined reference to `F1'
  </code></pre>
  
  <p>What is wrong?</p>
  
  <p>Thank you.</p>
  
  <p>ETA: Thanks to the answers I've received, I now have the following:</p>
  
  <p>In fileA.h, I have</p>
  
  <pre><code>#include fileB.h
  #include main.h
  
  #ifdef __cplusplus
  extern "C" 
  #endif
  void F1();
  </code></pre>
  
  <p>In fileA.c, I have</p>
  
  <pre><code>#include fileA.h
  </code></pre>
  
  <p>In fileB.h, I have</p>
  
  <pre><code>extern "C" void F1();
  </code></pre>
  
  <p>In fileB.cpp, I have</p>
  
  <pre><code>#include "fileB.h"
  
  extern "C" void F1()
  { }
  </code></pre>
  
  <p>However, I now have the error</p>
  
  <pre><code>fileB.h: error: expected identifier or '(' before string constant
  </code></pre>