title: undefined reference to `cudaFree' and many other errors when compileing program
body: <p>When I try to compile my CUDA program, I get the following errors:</p>
  
  <pre><code>b.o: In function `mul_wrapper':
  /tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0xcb): undefined reference to `cudaConfigureCall'
  /tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0xe7): undefined reference to `cudaDeviceSynchronize'
  /tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x144): undefined reference to `cudaFree'
  b.o: In function `cudaError cudaMallocManaged&lt;float&gt;(float**, unsigned long, unsigned int)':
  /tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x18a): undefined reference to `cudaMallocManaged'
  b.o: In function `__device_stub__Z3mulPf(float*)':
  /tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x1df): undefined reference to `cudaSetupArgument'
  b.o: In function `cudaError cudaLaunch&lt;char&gt;(char*)':
  /tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x221): undefined reference to `cudaLaunch'
  b.o: In function `__sti____cudaRegisterAll_36_tmpxft_00002a64_00000000_7_b_cpp1_ii__Z3mulPf()':
  /tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x243): undefined reference to `__cudaRegisterFatBinary'
  b.o: In function `__nv_cudaEntityRegisterCallback(void**)':
  /tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x2f2): undefined reference to `__cudaRegisterFunction'
  b.o: In function `__cudaUnregisterBinaryUtil()':
  /tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x31b): undefined reference to `__cudaUnregisterFatBinary'
  collect2: error: ld returned 1 exit status
  Makefile:3: recipe for target 'run' failed
  make: *** [run] Error 1
  </code></pre>
  
  <p>My make file looks like this:</p>
  
  <pre><code>run: main.o b.o
  
      gcc -fPIC -L /usr/local/cuda/lib -lcudart -o run main.o b.o
  
  
  
  main.o: main.c b.h
  
      gcc -fPIC -I /usr/local/cuda/include -c -o main.o main.c
  
  
  
  b.o: b.cu b.h
  
      nvcc -Xcompiler -fPIC -ccbin clang-3.8 -c -o b.o b.cu
  </code></pre>
  
  <p>It seems like the problem has to do with the files "/usr/local/cuda/include" and "/usr/local/cuda/lib" not being found on my system. I am using Ubuntu 17.04 and have installed the CUDA toolkit with apt. I heard that installing CUDA toolkit with apt doesn't create the /usr/local/cuda/* files, so I tried to install it from the run file, but that faild to install.  </p>
  
  <p>UPDATE: I reinstalled CUDA toolkit and now I have the /usr/local/cuda/* directory, but the problem still persists.</p>