title: How to Link a third Party Library (LibUSB) in CMake
body: <p>I am attempting to use LibUSB in a project. However whenever I attempt to use basic libUSB functions I get the following error: </p>
  
  <pre><code>...src/main/main.cpp.o: In function `main':
  ...src/main/main.cpp:10: undefined reference to `libusb_init'
  ...src/main/main.cpp:11: undefined reference to `libusb_set_debug'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>The package LibUSB-devel is installed (I'm on fedora 22) and my IDE KDevelop finds and recognises the headers, to the point it offers LibUSB code completions once you have added the import statement. I don't have any custom include lines in either my IDE or CMake (my build system) so I would like to know what I need to to to make CMake find the LibUSB headers.</p>
  
  <p>This is the contents of <code>main.cpp</code>, just in case I messed something up:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;libusb-1.0/libusb.h&gt;
  
  int main(int argc, char **argv) {
        libusb_init(NULL);
        libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_WARNING);
  
        /*snip*/
  
        std::cout &lt;&lt; "Hello, world! PTPID="  &lt;&lt; std::endl;
        return 0;
  }
  </code></pre>
  
  <p>The following are the <code>CMakeLists.txt</code>:<br>
  ../</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8.11)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  set(CMAKE_BUILD_TYPE Debug)
  
  project(aProjectThatHasHadIt'sNameObcured)
  add_subdirectory(src)
  </code></pre>
  
  <p>.../src/cmakelists.txt just adds subdirectories</p>
  
  <p>.../src/main/</p>
  
  <pre><code>add_executable(main main.cpp)
  </code></pre>