title: A mix of c++ and cublas code isn't compiling
body: <p>So I have this code that's suppose to compute the dot product of a matrix in different ways (one of which is to use blas in a c++), but when I try to use nvcc to compile the code, it doesn't work and it says that I have an undefined reference to ddot. This is weird because I'm pretty sure I'm using the calling notation referenced here for cublas: <a href="http://www.sdsc.edu/us/training/assets/docs/NVIDIA-03-Toolkit.pdf" rel="nofollow">http://www.sdsc.edu/us/training/assets/docs/NVIDIA-03-Toolkit.pdf</a></p>
  
  <p>Can anyone help me? Here's a snip of code I'm having trouble with:</p>
  
  <pre><code>#include &lt;cublas.h&gt; //just some included files here. No problems with these
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  using namespace std;
  
  extern "C" //This is where I mention the cublas functions are external.
  //I think this is necessary since I also have cuda pieces of code
  {
      double cublasDDOT_(int *n, double *A, int *incA, double *B, int *incB);
  
      void cublasDAXPY_(int *n, double *a, double *A, int *incA, double *B, int *incB);
  }
  
  //Stuff happens here
  
  C[i][t]=cublasDDOT_(&amp;n, partA, &amp;incA, partB, &amp;incB); //This is a piece of my function and where the compiler chokes up
  </code></pre>
  
  <p>This is weird to me. I've also tried removing the "_"'s with no luck.</p>
  
  <p>Here's the compile command I use: <code>nvcc program</code></p>
  
  <p>Do I need to mention the cublas library during the compile somehow? I have the cuda toolkit installed, but I don't know how to reference the library other than with</p>
  
  <p><code>#include &lt;cublas.h&gt;</code></p>
  
  <p><strong>New update</strong></p>
  
  <p>It turns out I get the same output whether I include the cublas.h header or not</p>
  
  <p>I also get the same output whether I type -lcublas or not</p>
  
  <p>Here's the output, which is garbage for all compiles (with/without cublas.h &amp; with/without -lcublas)</p>
  
  <pre><code>nvcc project4.cu -lcublas
  /tmp/tmpxft_000051cb_00000000-14_project4.o: In function `ddot(int&amp;, int&amp;, int&amp;, double**&amp;, double**&amp;, double**&amp;, double*&amp;, double*&amp;, int&amp;, int&amp;, double&amp;, double&amp;, double*)':
  tmpxft_000051cb_00000000-3_project4.cudafe1.cpp:(.text+0xda1): undefined reference to `cublasDDOT'
  /tmp/tmpxft_000051cb_00000000-14_project4.o: In function `daxpy(int&amp;, int&amp;, int&amp;, double**&amp;, double**&amp;, double**&amp;, double**&amp;, double*&amp;, double*&amp;, int&amp;, int&amp;, double&amp;, double&amp;, double*)':
  tmpxft_000051cb_00000000-3_project4.cudafe1.cpp:(.text+0xff3): undefined reference to `cublasDAXPY'
  collect2: ld returned 1 exit status
  </code></pre>