title: How to specify non-default shared-library path in GCC Linux? Getting "error while loading shared libraries" when running
body: <p>There is a laptop on which I have no root privilege.</p>
  <p>onto the machine I have a library installed using <code>configure --prefix=$HOME/.usr</code> .</p>
  <p>after that, I got these files in <code>~/.usr/lib</code> :</p>
  <pre><code>libXX.so.16.0.0
  libXX.so.16
  libXX.so
  libXX.la
  libXX.a
  </code></pre>
  <p>when I compile a program that invokes one of function provided by the library with this command :
  <code>gcc XXX.c -o xxx.out -L$HOME/.usr/lib -lXX</code></p>
  <p>xxx.out was generated without warning, but when I run it error like this was thrown:</p>
  <p><code>./xxx.out: error while loading shared libraries: libXX.so.16: cannot open shared object file: No such file or directory</code> , though <code>libXX.so.16</code> resides there.</p>
  <p>my clue-less assumption is that <code>~/.usr/lib</code> wasn't searched when xxx.out is invoked.
  but what can I do to specify path of .so , in order that xxx.out can look there for .so file?</p>
  <p>An addition is when I feed <code>-static</code> to gcc, another error happens like this:</p>
  <pre><code>undefined reference to `function_proviced_by_the_very_librar'
  </code></pre>
  <p>It seems <code>.so</code> does not matter even though <code>-L</code> and <code>-l</code> are given to gcc.
  what should I do to build a usable exe with that library?</p>
  <hr />
  <h3>For other people who has the same question as I did</h3>
  <p>I found <a href="http://tldp.org/HOWTO/Program-Library-HOWTO/index.html" rel="noreferrer">a useful article at tldp</a> about this.</p>
  <p>It introduces static/shared/dynamic loaded library, as well as some example code to use them.</p>