title: GCC: Linking a dylib on Mac Os
body: <p><code>gcc</code> is unable to find a dynamic library if I don't specify its path explicitly. First of all I'm using <code>libmemcached</code> which I've got installed with <code>brew</code>.</p>
  
  <pre><code>17:27:14 shell% ls -la /usr/local/lib/libmemcached*
  lrwxr-xr-x  1 user  wheel  55 Sep  2 12:42 /usr/local/lib/libmemcached.11.dylib -&gt; ../Cellar/libmemcached/1.0.17/lib/libmemcached.11.dylib
  lrwxr-xr-x  1 user  wheel  48 Sep  2 12:42 /usr/local/lib/libmemcached.a -&gt; ../Cellar/libmemcached/1.0.17/lib/libmemcached.a
  lrwxr-xr-x  1 user  wheel  52 Sep  2 12:42 /usr/local/lib/libmemcached.dylib -&gt; ../Cellar/libmemcached/1.0.17/lib/libmemcached.dylib
  lrwxr-xr-x  1 user  wheel  58 Sep  2 12:42 /usr/local/lib/libmemcachedutil.2.dylib -&gt; ../Cellar/libmemcached/1.0.17/lib/libmemcachedutil.2.dylib
  lrwxr-xr-x  1 user  wheel  52 Sep  2 12:42 /usr/local/lib/libmemcachedutil.a -&gt; ../Cellar/libmemcached/1.0.17/lib/libmemcachedutil.a
  lrwxr-xr-x  1 user  wheel  56 Sep  2 12:42 /usr/local/lib/libmemcachedutil.dylib -&gt; ../Cellar/libmemcached/1.0.17/lib/libmemcachedutil.dylib
  </code></pre>
  
  <p>My <code>hellomemcached.c</code> looks like this:</p>
  
  <pre><code>#include &lt;libmemcached/memcached.h&gt;
  
  int main ()
  {
      memcached_return_t  rc;
      memcached_server_st*    servers = NULL;
      memcached_st*       memcached;
  
      // initialize the memcached structure
      memcached = memcached_create(NULL);
      if (!memcached)
          return 0;
  }
  </code></pre>
  
  <p>The compilation with the following command ends with success:</p>
  
  <pre><code>gcc -arch x86_64 /usr/local/lib/libmemcached.dylib -I/usr/local/include -o hellomemcached hellomemcached.c
  </code></pre>
  
  <p>But if I try to compile it with a path to the folder, which contains the library:</p>
  
  <pre><code>gcc -arch x86_64 -L/usr/local/lib -I/usr/local/include -o hellomemcached hellomemcached.c
  </code></pre>
  
  <p>I get an error:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
      "_memcached_create", referenced from:
      _main in ccYCwHa6.o
  ld: symbol(s) not found for architecture x86_64
  </code></pre>
  
  <p>Apparently it can't find the library in that case. What I'm doing wrong?</p>