title: g++ executable cannot find shared library
body: <p>I was working with libevent 2.X at office. At home I have Ubuntu 10.4 which provides libevent 1.4 , so I downloaded and compiled the latest version of libevent. Now I have the header in /usr/local/include and library file in /usr/local/lib. But my problem is that the executable does not seem to find the correct library. </p>
  
  <p>I tried this</p>
  
  <pre><code>vickey@home:~/development/Server/test$ g++ Server.cpp -L /usr/local/lib -levent -I /usr/local/include/
  
  vickey@home:~/development/Server/test$ ./a.out 
  ./a.out: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
  </code></pre>
  
  <p>The verbose output of compilation is below </p>
  
  <pre><code>vickey@home:~/development/Server/test$ g++ Server.cpp -L /usr/local/lib -levent -I /usr/local/include/ -v
  Using built-in specs.
  Target: i486-linux-gnu
  Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
  Thread model: posix
  gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) 
  COLLECT_GCC_OPTIONS='-L' '/usr/local/lib' '-I' '/usr/local/include/' '-v' '-shared-libgcc' '-mtune=generic' '-march=i486'
   /usr/lib/gcc/i486-linux-gnu/4.4.3/cc1plus -quiet -v -I /usr/local/include/ -D_GNU_SOURCE Server.cpp -D_FORTIFY_SOURCE=2 -quiet -dumpbase Server.cpp -mtune=generic -march=i486 -auxbase Server -version -fstack-protector -o /tmp/cceeQ3Uc.s
  GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (i486-linux-gnu)
      compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1.
  GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
  ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
  ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../i486-linux-gnu/include"
  ignoring nonexistent directory "/usr/include/i486-linux-gnu"
  ignoring duplicate directory "/usr/local/include/"
    as it is a non-system directory that duplicates a system directory
  #include "..." search starts here:
  #include &lt;...&gt; search starts here:
   /usr/include/c++/4.4
   /usr/include/c++/4.4/i486-linux-gnu
   /usr/include/c++/4.4/backward
   /usr/local/include
   /usr/lib/gcc/i486-linux-gnu/4.4.3/include
   /usr/lib/gcc/i486-linux-gnu/4.4.3/include-fixed
   /usr/include
  End of search list.
  GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (i486-linux-gnu)
      compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1.
  GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
  Compiler executable checksum: 35224f2c24023afb0a5be7befe8d5f3f
  COLLECT_GCC_OPTIONS='-L' '/usr/local/lib' '-I' '/usr/local/include/' '-v' '-shared-libgcc' '-mtune=generic' '-march=i486'
   as -V -Qy -o /tmp/cclpymAs.o /tmp/cceeQ3Uc.s
  GNU assembler version 2.20.1 (i486-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.20.1-system.20100303
  COMPILER_PATH=/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/
  LIBRARY_PATH=/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../:/lib/:/usr/lib/:/usr/lib/i486-linux-gnu/
  COLLECT_GCC_OPTIONS='-L' '/usr/local/lib' '-I' '/usr/local/include/' '-v' '-shared-libgcc' '-mtune=generic' '-march=i486'
   /usr/lib/gcc/i486-linux-gnu/4.4.3/collect2 --build-id --eh-frame-hdr -m elf_i386 --hash-style=both -dynamic-linker /lib/ld-linux.so.2 -z relro /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o /usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o -L /usr/local/lib -L/usr/lib/gcc/i486-linux-gnu/4.4.3 -L/usr/lib/gcc/i486-linux-gnu/4.4.3 -L/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/i486-linux-gnu/4.4.3/../../.. -L/usr/lib/i486-linux-gnu /tmp/cclpymAs.o -levent -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crtn.o
  </code></pre>