title: loading a shared library from any directory
body: <p>I'm playing with shared library linking and loading procedures, and trying to learn about different ways to tackle the loading error:</p>
  
  <p><code>error while loading shared libraries: ... : cannot open shared object file: No such file or directory</code></p>
  
  <p>I managed to solve it by using LD_LIBRARY_PATH and by using rpath. I now try to comprehend the usage of ldconfig and how it can solve it, too [some of my web sources: <a href="http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html#fnref:2" rel="nofollow">1</a>, <a href="http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html" rel="nofollow">2</a>, <a href="http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html" rel="nofollow">3</a> ]</p>
  
  <p>So, I've got the following source files: <code>test.c func1.c func2.c</code>. Here's what I do:</p>
  
  <ol>
  <li>Compiling them into PIC .obj files:</li>
  </ol>
  
  <p><code>$ gcc -Wall -fPIC -c *.c</code></p>
  
  <ol start="2">
  <li>Creating a shared library from the object files, naming it 'libshared.so', and using 'soname':</li>
  </ol>
  
  <p><code>$ gcc -shared -Wl,-soname,libshared.so -o libshared.so *.o</code></p>
  
  <ol start="3">
  <li>Linking with a shared library by telling GCC where to find the shared library (the <code>...</code> is just an abbreviation for my personal shared library path):</li>
  </ol>
  
  <p><code>$ gcc -L/home/.../my_shared_library -Wall -o mytest test.c -lshared</code></p>
  
  <ol start="4">
  <li>Now, I try running it, and get the loading error:</li>
  </ol>
  
  <p><code>./mytest: error while loading shared libraries: libshared.so: cannot open shared object file: No such file or directory</code></p>
  
  <ol start="5">
  <li>So I try telling the loader to search my private directory for the shared library file:</li>
  </ol>
  
  <p><code>ldconfig -n home/.../my_shared_library</code></p>
  
  <p>(I also tried it with: <code>ldconfig -n .-L</code> when my working directory is home/.../my_shared_library) </p>
  
  <p>and tried running it once again, but I still get the same error. What am I doing wrong?</p>