title: gcc cannot find function in lib
body: <p>I am trying to make a C program using libmbus, which I have installed on my raspberry pi. In my /usr/lib directory I have the file libmbus.so and in my /usr/include directory I have the the file ./mbus/mbus.h.</p>
  
  <p>The program looks like this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;mbus/mbus.h&gt;
  
  int main(void)
  {
      mbus_handle* MbusHandle;
  
      MbusHandle = mbus_connect_serial("/dev/ttyS1");
  
      return 0;
  }
  </code></pre>
  
  <p>When I try to run "gcc main.cpp -lmbus" I get:</p>
  
  <pre><code>main.cpp:(.text+0xe): undefined reference to `mbus_connect_serial(char const*)'
  </code></pre>
  
  <p>I tried to run</p>
  
  <pre><code>nm -D /usr/lib/libmbus.so
  </code></pre>
  
  <p>which among others gives</p>
  
  <pre><code>00009930 T mbus_connect_serial
  </code></pre>
  
  <p>So it appears that the function mbus_connect_serial is part of libmbus.so.</p>
  
  <p>In the header file the function mbus_connect_serial is defined like this:</p>
  
  <pre><code>mbus_handle * mbus_connect_serial(const char * device);
  </code></pre>
  
  <p>I can't seem to figure out what is wrong. Can anyone guide me in the right direction?</p>