title: g++ linking problem
body: <p>I'm having a weird linking problem and am only beginning programming with c++ so I'm not terribly sure what it means...</p>
  
  <p><strong>main.cpp</strong> </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  main(void)
  {
   return 0;
  }
  </code></pre>
  
  <p><strong>Compiling</strong></p>
  
  <pre><code>esr@athena:~/programming/cpp$ g++ main.cpp 
  esr@athena:~/programming/cpp$ ./a.out 
  esr@athena:~/programming/cpp$ g++ main.cpp -L/home/esr/ogre/lib -lOgreMain
  esr@athena:~/programming/cpp$ ./a.out 
  </code></pre>
  
  <p>This executes just fine, however, when I link against another of the libraries in the same folder...</p>
  
  <pre><code>esr@athena:~/programming/cpp$ g++ main.cpp -L/home/esr/ogre/lib -lOgreMain -lOgreTerrain
  esr@athena:~/programming/cpp$ ./a.out 
  ./a.out: error while loading shared libraries: libOgreTerrain.so.1.7.1: cannot open shared object file: No such file or directory
  </code></pre>
  
  <p>So what's in that folder?</p>
  
  <pre><code>esr@athena:~/programming/cpp$ ls /home/esr/ogre/lib/
  libOgreMain.so                  Sample_DynTex.so
  libOgreMain.so.1.7.1           Sample_FacialAnimation.so
  libOgrePaging.so                Sample_Fresnel.so
  libOgrePaging.so.1.7.1          Sample_Grass.so
  libOgreRTShaderSystem.so        Sample_Instancing.so
  libOgreRTShaderSystem.so.1.7.1  Sample_Isosurf.so
  libOgreTerrain.so               Sample_Lighting.so
  ***libOgreTerrain.so.1.7.1***         Sample_Ocean.so
  </code></pre>
  
  <p>Edit: (the stars are for emphasis, not a file name)
  It's right there! Any ideas on what I'm doing wrong?</p>
  
  <h2>Edit</h2>
  
  <p>Still having problems. Tried linking against all dependencies of libOgreTerrain and that doesn't seem to have satisfied the compiler. </p>
  
  <pre><code>ldd libOgreTerrain.so
      linux-vdso.so.1 =&gt;  (0x00007fff56bff000)
      libOgreMain.so.1.7.1 =&gt; /home/esr/ogre/lib/libOgreMain.so.1.7.1 (0x00007fd3584c8000)
      libOgrePaging.so.1.7.1 =&gt; /home/esr/ogre/lib/libOgrePaging.so.1.7.1 (0x00007fd35829b000)
      libfreetype.so.6 =&gt; /usr/lib/libfreetype.so.6 (0x00007fd357fee000)
      libSM.so.6 =&gt; /usr/lib/libSM.so.6 (0x00007fd357de5000)
      libICE.so.6 =&gt; /usr/lib/libICE.so.6 (0x00007fd357bca000)
      libX11.so.6 =&gt; /usr/lib/libX11.so.6 (0x00007fd357893000)
      libXext.so.6 =&gt; /usr/lib/libXext.so.6 (0x00007fd357681000)
      libXt.so.6 =&gt; /usr/lib/libXt.so.6 (0x00007fd35741c000)
      libXaw.so.7 =&gt; /usr/lib/libXaw.so.7 (0x00007fd3571ac000)
      libpthread.so.0 =&gt; /lib/libpthread.so.0 (0x00007fd356f8f000)
      libdl.so.2 =&gt; /lib/libdl.so.2 (0x00007fd356d8b000)
      libfreeimage.so.3 =&gt; /usr/lib/libfreeimage.so.3 (0x00007fd3568bc000)
      libzzip-0.so.13 =&gt; /usr/lib/libzzip-0.so.13 (0x00007fd3566b5000)
      libz.so.1 =&gt; /lib/libz.so.1 (0x00007fd35649d000)
      libstdc++.so.6 =&gt; /usr/lib/libstdc++.so.6 (0x00007fd356196000)
      libm.so.6 =&gt; /lib/libm.so.6 (0x00007fd355f13000)
      libgcc_s.so.1 =&gt; /lib/libgcc_s.so.1 (0x00007fd355cfd000)
      libc.so.6 =&gt; /lib/libc.so.6 (0x00007fd355979000)
      libuuid.so.1 =&gt; /lib/libuuid.so.1 (0x00007fd355774000)
      libxcb.so.1 =&gt; /usr/lib/libxcb.so.1 (0x00007fd355556000)
      libXmu.so.6 =&gt; /usr/lib/libXmu.so.6 (0x00007fd35533d000)
      libXpm.so.4 =&gt; /usr/lib/libXpm.so.4 (0x00007fd35512c000)
      libXau.so.6 =&gt; /usr/lib/libXau.so.6 (0x00007fd354f28000)
      libXdmcp.so.6 =&gt; /usr/lib/libXdmcp.so.6 (0x00007fd354d22000)
  </code></pre>
  
  <p>Changed compilation code to the following:</p>
  
  <pre><code>g++ main.cpp -L/home/esr/ogre/lib -lOgreMain -lOgreTerrain -L/lib -L/usr/lib -lfreetype -lSM -lICE -lX11 -lXext -lXt -lXaw -lpthread -lfreeimage  -lxcb -lXmu -lXpm -lXau -lXdmcp -ldl -lzzip -lz -lstdc++ -lm -lgcc_s -lc 
  </code></pre>
  
  <p>Which links against all dependencies as above afaik (uuid wouldn't link).</p>
  
  <pre><code>esr@athena:~/programming/cpp$ g++ main.cpp -L/home/esr/ogre/lib -lOgreMain -lOgreTerrain -L/lib -L/usr/lib -lfreetype -lSM -lICE -lX11 -lXext -lXt -lXaw -lpthread -lfreeimage  -lxcb -lXmu -lXpm -lXau -lXdmcp -ldl -lzzip -lz -lstdc++ -lm -lgcc_s -lc 
  esr@athena:~/programming/cpp$ ./a.out 
  ./a.out: error while loading shared libraries: libOgreTerrain.so.1.7.1: cannot open shared object file: No such file or directory
  esr@athena:~/programming/cpp$ LD_LIBRARY_PATH=/home/esr/ogre/lib ./a.out
  esr@athena:~/programming/cpp$ 
  </code></pre>
  
  <h2>Edit 2</h2>
  
  <p>Linking of a.out</p>
  
  <pre><code>esr@athena:~/programming/cpp$ ldd a.out 
      linux-vdso.so.1 =&gt;  (0x00007fff978a4000)
      libOgreMain.so.1.7.1 =&gt; /usr/lib/libOgreMain.so.1.7.1 (0x00007f612d528000)
      libOgreTerrain.so.1.7.1 =&gt; not found
      libfreetype.so.6 =&gt; /usr/lib/libfreetype.so.6 (0x00007f612d2a0000)
      libSM.so.6 =&gt; /usr/lib/libSM.so.6 (0x00007f612d097000)
      libICE.so.6 =&gt; /usr/lib/libICE.so.6 (0x00007f612ce7c000)
      libX11.so.6 =&gt; /usr/lib/libX11.so.6 (0x00007f612cb45000)
      libXext.so.6 =&gt; /usr/lib/libXext.so.6 (0x00007f612c933000)
      libXt.so.6 =&gt; /usr/lib/libXt.so.6 (0x00007f612c6ce000)
      libXaw.so.7 =&gt; /usr/lib/libXaw.so.7 (0x00007f612c45e000)
      libpthread.so.0 =&gt; /lib/libpthread.so.0 (0x00007f612c241000)
      libfreeimage.so.3 =&gt; /usr/lib/libfreeimage.so.3 (0x00007f612bd73000)
      libxcb.so.1 =&gt; /usr/lib/libxcb.so.1 (0x00007f612bb55000)
      libXmu.so.6 =&gt; /usr/lib/libXmu.so.6 (0x00007f612b93c000)
      libXpm.so.4 =&gt; /usr/lib/libXpm.so.4 (0x00007f612b72b000)
      libXau.so.6 =&gt; /usr/lib/libXau.so.6 (0x00007f612b527000)
      libXdmcp.so.6 =&gt; /usr/lib/libXdmcp.so.6 (0x00007f612b321000)
      libdl.so.2 =&gt; /lib/libdl.so.2 (0x00007f612b11d000)
      libzzip-0.so.13 =&gt; /usr/lib/libzzip-0.so.13 (0x00007f612af15000)
      libz.so.1 =&gt; /lib/libz.so.1 (0x00007f612acfd000)
      libstdc++.so.6 =&gt; /usr/lib/libstdc++.so.6 (0x00007f612a9f7000)
      libgcc_s.so.1 =&gt; /lib/libgcc_s.so.1 (0x00007f612a7e0000)
      libm.so.6 =&gt; /lib/libm.so.6 (0x00007f612a55d000)
      libc.so.6 =&gt; /lib/libc.so.6 (0x00007f612a1da000)
      libuuid.so.1 =&gt; /lib/libuuid.so.1 (0x00007f6129fd4000)
      /lib64/ld-linux-x86-64.so.2 (0x00007f612dcfc000)
  </code></pre>
  
  <h1>Resolution</h1>
  
  <p>Partially resolved thusly, I linked to the shared libraries in the /usr/lib folder, I'm not sure why g++ wouldn't look in there, but it just wouldn't. </p>
  
  <p>Useful links <a href="http://linuxmafia.com/faq/Admin/ld-lib-path.html" rel="nofollow">here</a> and <a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html" rel="nofollow">here</a></p>