title: how can I link a shared object in C?
body: <p>I made a simple program that uses a shared object, opening it with <code>dlopen()</code>. I also compiled and linked the shared object like below:</p>
  
  <pre><code>gcc -o libmylib.so libmylib.c -shared -fPIC -Wall
  
  gcc -o program program.c -L. -lmylib -ldl -Wall
  </code></pre>
  
  <p>When I tried to run the program for the first time it said something like </p>
  
  <pre><code>cannot open libmylib.so: no such file or directory
  </code></pre>
  
  <p>so I searched the internet and found that I have to copy my shared object to <code>/lib/i386-linux-gnu/</code> in order for the program to run. So I did so, and it worked, but then I tried to do it in other ways and therefore I removed <code>libmylib.so</code> from the <code>/lib/i3686-linux-gnu/</code> directory. Now when I'm trying to run the program it shown no errors but keeps saying <code>Segmentation fault</code>. It is clear that the shared object is nowhere to be found, but how can I link it without copying anything?</p>
  
  <p>I am using Ubuntu 11.10</p>