title: cblas linking: undefined reference to `cblas_dgemv'
body: <p>I am trying to use cblas library to use BLAS. I call cblas function from a custom C function and then link this file to my C++ file. But I get this error </p>
  
  <pre><code>Cfile.o: In function `mm_blas':
  Cfile.c:(.text+0xbf): undefined reference to `cblas_dgemv'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>My <strong>Cfile.c</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;cblas.h&gt;
  
  void f(double dd[])
  {
      int i;
        for (i=0; i&lt;2; ++i)  printf("%5.1f\n", dd[i]);
      printf("\n This is a C code\n");
  }
  
      double m[] = {
    3, 1, 3,
    1, 5, 9,
    2, 6, 5
  };
  
  double x[] = {
    -1, -1, 1
  };
  
  double y[] = {
    0, 0, 0
  };
  
  void mm_blas(double m1[], double m2[], double m3[], int m_size){
    cblas_dgemv(CblasRowMajor, CblasNoTrans, 3, 3, 1.0, m, 3, x, 1, 0.0, y, 1);
  }
  </code></pre>
  
  <p><strong>And main.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;random&gt;
  #include &lt;chrono&gt;
  #include &lt;time.h&gt;
  #include &lt;string&gt;
  #include &lt;algorithm&gt;
  #include &lt;ostream&gt;
  
  using namespace std;
  using namespace std::chrono;
  
  extern "C" {
      #include &lt;stdio.h&gt;
      #include &lt;cblas.h&gt;
  
      void f(double []);
      void mm_blas(double [], double [], double [], int);
  }
  
  void func(void)
  {
      std::cout&lt;&lt;"\n being used within C++ code\n";
  }
  
  int main(void)
  {
      double dd [] = {1,2,3};
      f(dd);
      func();
      return 0;
  }
  </code></pre>
  
  <p>I compile the code with command</p>
  
  <pre><code>gcc -c -lblas Cfile.c -o Cfile.o  &amp;&amp; g++ -std=c++11 -lblas -o  myfoobar Cfile.o main.cpp &amp;&amp; ./myfoobar
  </code></pre>
  
  <p>I am on Linux, gcc 4.8. How to solve this problem.</p>