title: Linking error c and c++ (undefined reference)
body: <h1>abc.c file</h1>
  
  <pre><code>#include "abc.h"
  int abc()
  {
      return 10;
  }
  </code></pre>
  
  <h1>abc.h file</h1>
  
  <pre><code>int abc();
  </code></pre>
  
  <h1>mymain.cpp file</h1>
  
  <pre><code>#include "abc.h"
  int main()
  {
      abc();
      return  0;
  }
  </code></pre>
  
  <h1>Makefile</h1>
  
  <pre><code>CC=gcc -O2 
  CP=g++
  
  mymain: mymain.o abc.o
      $(CP) -o mymain mymain.o abc.o
  
  mymain.o: mymain.cpp abc.h
      $(CP) -c mymain.cpp abc.h
  
  abc.o: abc.c abc.h
      $(CC) -c abc.c abc.h
  
  clean:  
      $(RM) *.o mymain
  </code></pre>
  
  <h1>output</h1>
  
  <pre><code>g++ -c mymain.cpp abc.h
  gcc -O2  -c abc.c abc.h
  g++ -o mymain mymain.o abc.o
  mymain.o: In function `main':
  mymain.cpp:(.text+0x5): undefined reference to `abc()'
  collect2: error: ld returned 1 exit status
  make: *** [mymain] Error 1
  </code></pre>
  
  <p>Why abc() is undefined reference ??</p>
  
  <h1>UPDATE</h1>
  
  <h1>new abc.h</h1>
  
  <pre><code>extern "C" {
      int abc();
  }
  </code></pre>
  
  <h1>error</h1>
  
  <pre><code>g++ -c mymain.cpp abc.h
  gcc -O2  -c abc.c abc.h
  In file included from abc.c:1:0:
  abc.h:1:8: error: expected identifier or ‘(’ before string constant
   extern "C" {
          ^
  abc.h:1:8: error: expected identifier or ‘(’ before string constant
   extern "C" {
          ^
  make: *** [abc.o] Error 1
  </code></pre>