title: Linking against libusb on Ubuntu doesn't work
body: <p>We're trying to compile some code on an Ubuntu box that requires libusb but we keep getting "undefined reference to" errors when it tries to link against it.</p>
  
  <p>The code in question is this one:
  <a href="https://gitorious.org/minibox-dcdcusb/minibox-dcdcusb" rel="nofollow">https://gitorious.org/minibox-dcdcusb/minibox-dcdcusb</a></p>
  
  <p>It requires libusb so I install that:</p>
  
  <pre><code>apt-get install libusb libusb-dev
  </code></pre>
  
  <p>Then I run make and get the following errors:</p>
  
  <pre><code>➜  minibox-dcdcusb git:(master) ✗ make                    
  cc -Wall  main.c -o dcdc-usb `pkg-config --libs libusb` -lm -L. -ldcdc-usb
  ./libdcdc-usb.so: undefined reference to `usb_get_driver_np'
  ./libdcdc-usb.so: undefined reference to `usb_interrupt_read'
  ./libdcdc-usb.so: undefined reference to `usb_find_busses'
  ./libdcdc-usb.so: undefined reference to `usb_find_devices'
  ./libdcdc-usb.so: undefined reference to `usb_set_configuration'
  ./libdcdc-usb.so: undefined reference to `usb_interrupt_write'
  ./libdcdc-usb.so: undefined reference to `usb_control_msg'
  ./libdcdc-usb.so: undefined reference to `usb_set_altinterface'
  ./libdcdc-usb.so: undefined reference to `usb_init'
  ./libdcdc-usb.so: undefined reference to `usb_set_debug'
  ./libdcdc-usb.so: undefined reference to `usb_open'
  ./libdcdc-usb.so: undefined reference to `usb_claim_interface'
  ./libdcdc-usb.so: undefined reference to `usb_detach_kernel_driver_np'
  ./libdcdc-usb.so: undefined reference to `floor'
  ./libdcdc-usb.so: undefined reference to `usb_get_busses'
  collect2: error: ld returned 1 exit status
  make: *** [dcdc-usb] Error 1
  </code></pre>
  
  <p>I have verified that pkg-config is reporting the proper config params:</p>
  
  <pre><code>➜  minibox-dcdcusb git:(master) ✗ pkg-config --libs libusb
  -lusb  
  </code></pre>
  
  <p>And I've made sure that the binaries are where they're supposed to be:</p>
  
  <pre><code>➜  minibox-dcdcusb git:(master) ✗ ls -l /usr/lib/x86_64-linux-gnu/libusb*
  lrwxrwxrwx 1 root root    37 des  3 13:58 /usr/lib/x86_64-linux-gnu/libusb-0.1.so.4 -&gt; /lib/x86_64-linux-gnu/libusb-0.1.so.4
  -rw-r--r-- 1 root root 42998 des  3 13:58 /usr/lib/x86_64-linux-gnu/libusb.a
  lrwxrwxrwx 1 root root    41 des  3 13:58 /usr/lib/x86_64-linux-gnu/libusb.so -&gt; /lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4
  </code></pre>
  
  <p>And I've even made sure that the references that the linker seems to be complaining about are actually in the libusb binaries:</p>
  
  <ul>
  <li><a href="http://pastie.org/9156632" rel="nofollow">http://pastie.org/9156632</a></li>
  <li><a href="http://pastie.org/9156633" rel="nofollow">http://pastie.org/9156633</a></li>
  </ul>
  
  <p>(spoiler: all the symbols that the linker complains about seem to be there)</p>
  
  <p>Finally, I ran the compile command with -Wl,--verbose to see exactly what binaries the linker was picking up and it seems that it is in fact picking up the correct binaries but it just isn't able to link against them. Here is the output of that:</p>
  
  <ul>
  <li><a href="http://pastie.org/9156644" rel="nofollow">http://pastie.org/9156644</a></li>
  </ul>
  
  <p>I'm quite lost as to what could possibly be the problem here? Why isn't the linker able to link against libusb?</p>