title: How to manually link libraries in g++ on Ubuntu
body: <p>Im trying to manually link external library with c++ on ubuntu. Since this is my first c++ project I'm missing some basics.
  This is my code (this tries to connect to spread):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sp.h&gt;
  
  using namespace std;
  
  int main() {
      int status;
      status = SP_connect("4803@localhost", "test1", 0, 0, 0, 0);
      cout &lt;&lt; "done\n";
      return 0;
  }
  </code></pre>
  
  <p>If I just try to run it with</p>
  
  <pre><code>user@computer:~/thesis$ g++ -o example1 test.cpp
  /tmp/cczPLZQ0.o: In function `main':
  test.cpp:(.text+0x39): undefined reference to `SP_connect'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>As far as I understand I need to link a library, I tried to do it with -l</p>
  
  <pre><code>kristjan@kupo:~/thesis$ g++ -o example1 test.cpp -llibspread
  /usr/bin/ld: cannot find -llibspread
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>I also tried this (I'm shooting in the dark here):</p>
  
  <pre><code>user@computer:~/thesis$ g++ -o example1 test.cpp $(pkg-config -cflags /usr/local/lib/libspread) $(pkg-config --libs /usr/local/lib/libspread)
  
  -cflags: unknown option
  Package /usr/local/lib/libspread was not found in the pkg-config search path.
  Perhaps you should add the directory containing `/usr/local/lib/libspread.pc'
  to the PKG_CONFIG_PATH environment variable
  No package '/usr/local/lib/libspread' found
  /tmp/ccU8GTC2.o: In function `main':
  test.cpp:(.text+0x39): undefined reference to `SP_connect'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>Any help would be appreciated.</p>