title: OpenCV C++/C compilation error: undefined reference to `cv::fastFree(void*)'
body: <p>I am trying to have a C program call a function in a C++ file that uses OpenCV.  I can get the C file to call a basic integer function in a C++ file and return a result, but whenever I try to add some OpenCV code to the C++ file, I get compilation errors.  Here is my simple code in each respective module:</p>
  
  <p><strong>foo.cpp</strong></p>
  
  <pre><code>#include &lt;time.h&gt;
  #include "opencv2/core/core.hpp"
  #include "opencv2/imgproc/imgproc.hpp"
  #include "opencv2/highgui/highgui.hpp"
  
  #include "opencv2/core/core.hpp"
  #include "opencv2/imgproc/imgproc.hpp"
  #include "opencv2/highgui/highgui.hpp"
  #include "opencv2/core/mat.hpp"
  #include "opencv/cv.hpp"
  
  #include &lt;iostream&gt;
  
  #ifdef _cplusplus 
  extern "C" int f(int);
  #endif 
  
  using namespace std;
  using namespace cv;
  
  int f(int i)
  {
  cout &lt;&lt; "CPP SON: " &lt;&lt; i &lt;&lt; endl;
  i--;
  
  //Mat image;
  
  //image = imread( "image1.jpg", 1 );
  
  //namedWindow( "image1.jpg", CV_WINDOW_AUTOSIZE );
  
  //imshow( "image1.jpg", image );
  
  //waitKey(0);
  
  return i;
  }
  </code></pre>
  
  <p><strong>bar.c</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int global = 0;
  
  int f(int);
  
  void cc(int i)
  {
      global = f(i);
      /* ... */
      printf("hello from C! %d \n", global);
  }
  
  int main(int argc, char *argv[]) {
  
      printf("this si is the C code called main\n");
      cc(32);
  
  
  }
  </code></pre>
  
  <p><strong>Makefile</strong></p>
  
  <pre><code>mot : foo.o bar.o
      g++ `pkg-config --cflags opencv` -o mot `pkg-config --libs opencv` foo.o bar.o
  
  foo.o : foo.cpp
      g++ `pkg-config --cflags opencv` -c foo.cpp `pkg-config --libs opencv` -o foo.o
  
  bar.o : bar.c
      g++ `pkg-config --cflags opencv` -c bar.c `pkg-config --libs opencv` -o bar.o
  
  clean : 
      rm foo.o
      rm bar.o
      rm mot
  </code></pre>
  
  <p>When commenting out all lines of OpenCV in the foo.cpp file, the following output is returned:</p>
  
  <pre><code>bi@rtes4:~/Desktop$ make
  g++ `pkg-config --cflags opencv` -c foo.cpp `pkg-config --libs opencv` -o foo.o
  g++ `pkg-config --cflags opencv` -c bar.c `pkg-config --libs opencv` -o bar.o
  g++ `pkg-config --cflags opencv` -o mot `pkg-config --libs opencv` foo.o bar.o
  bi@rtes4:~/Desktop$ ./mot
  this si is the C code called main
  CPP SON: 32
  hello from C! 31 
  </code></pre>
  
  <p>Upon commenting out the line "Mat image;" yields the following error:</p>
  
  <pre><code>bi@rtes4:~/Desktop$ make
  g++ `pkg-config --cflags opencv` -c foo.cpp `pkg-config --libs opencv` -o foo.o
  g++ `pkg-config --cflags opencv` -c bar.c `pkg-config --libs opencv` -o bar.o
  g++ `pkg-config --cflags opencv` -o mot `pkg-config --libs opencv` foo.o bar.o
  foo.o: In function `cv::Mat::~Mat()':
  foo.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
  foo.o: In function `cv::Mat::release()':
  foo.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to `cv::Mat::deallocate()'
  collect2: error: ld returned 1 exit status
  make: *** [mot] Error 1
  </code></pre>
  
  <p>Does anybody have any help they can lend?  Thank you kindly in advance for your assistance with this matter, it is greatly appreciated.</p>