title: gcc -L command confusion
body: <p>Let's say I have a shared library file, <code>libdemo.so</code>, where <code>libdemo.so</code> is the final linker.</p>
  
  <p>If I want to build the executable, and if the library file is in the current working directory, I link it in with the <code>-L. -ldemo</code> flags. </p>
  
  <p>But when I run the executable, unless I specify the library path, <code>LD_LIBRARY_PATH=.</code>, the executable can't find the link. So why the need for the extra <code>LD_LIBRARY_PATH</code> setting? The flags are for the link-time library path and the environment variable is the run-time library path supposedly.</p>
  
  <p>Alternatively, if I build the executable and specify a run-time library path using <code>-Wl,-rpath,.</code> I can omit <code>-L. -ldemo</code>.</p>
  
  <p>I know this has to do with link-time and run-time but I am unclear on what the difference is. For instance, when not using <code>-rpath</code>, what does the <code>-L. -ldemo</code> actually do if the executable needs <code>LD_LIBRARY_PATH</code> to find the library file? And when using the latter method, if specifying <code>-rpath</code> means copying the directory location into the run-time library path, why does this also allow the <code>-L. -ldemo</code> to be omitted? </p>
  
  <p>If the link-time library path and run-time library path are different, how come the latter method doesn't need the link-time library path when building? What is the difference between a link-time library path and run-time library path?</p>