views:

64

answers:

1

I'm having a weird linking problem and am only beginning programming with c++ so I'm not terribly sure what it means...

main.cpp

#include <iostream>

main(void)
{
 return 0;
}

Compiling

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 

This executes just fine, however, when I link against another of the libraries in the same folder...

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

So what's in that folder?

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

Edit: (the stars are for emphasis, not a file name) It's right there! Any ideas on what I'm doing wrong?

Edit

Still having problems. Tried linking against all dependencies of libOgreTerrain and that doesn't seem to have satisfied the compiler.

ldd libOgreTerrain.so
    linux-vdso.so.1 =>  (0x00007fff56bff000)
    libOgreMain.so.1.7.1 => /home/esr/ogre/lib/libOgreMain.so.1.7.1 (0x00007fd3584c8000)
    libOgrePaging.so.1.7.1 => /home/esr/ogre/lib/libOgrePaging.so.1.7.1 (0x00007fd35829b000)
    libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007fd357fee000)
    libSM.so.6 => /usr/lib/libSM.so.6 (0x00007fd357de5000)
    libICE.so.6 => /usr/lib/libICE.so.6 (0x00007fd357bca000)
    libX11.so.6 => /usr/lib/libX11.so.6 (0x00007fd357893000)
    libXext.so.6 => /usr/lib/libXext.so.6 (0x00007fd357681000)
    libXt.so.6 => /usr/lib/libXt.so.6 (0x00007fd35741c000)
    libXaw.so.7 => /usr/lib/libXaw.so.7 (0x00007fd3571ac000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x00007fd356f8f000)
    libdl.so.2 => /lib/libdl.so.2 (0x00007fd356d8b000)
    libfreeimage.so.3 => /usr/lib/libfreeimage.so.3 (0x00007fd3568bc000)
    libzzip-0.so.13 => /usr/lib/libzzip-0.so.13 (0x00007fd3566b5000)
    libz.so.1 => /lib/libz.so.1 (0x00007fd35649d000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fd356196000)
    libm.so.6 => /lib/libm.so.6 (0x00007fd355f13000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fd355cfd000)
    libc.so.6 => /lib/libc.so.6 (0x00007fd355979000)
    libuuid.so.1 => /lib/libuuid.so.1 (0x00007fd355774000)
    libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007fd355556000)
    libXmu.so.6 => /usr/lib/libXmu.so.6 (0x00007fd35533d000)
    libXpm.so.4 => /usr/lib/libXpm.so.4 (0x00007fd35512c000)
    libXau.so.6 => /usr/lib/libXau.so.6 (0x00007fd354f28000)
    libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007fd354d22000)

Changed compilation code to the following:

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 

Which links against all dependencies as above afaik (uuid wouldn't link).

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$ 

Edit 2

Linking of a.out

esr@athena:~/programming/cpp$ ldd a.out 
    linux-vdso.so.1 =>  (0x00007fff978a4000)
    libOgreMain.so.1.7.1 => /usr/lib/libOgreMain.so.1.7.1 (0x00007f612d528000)
    libOgreTerrain.so.1.7.1 => not found
    libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007f612d2a0000)
    libSM.so.6 => /usr/lib/libSM.so.6 (0x00007f612d097000)
    libICE.so.6 => /usr/lib/libICE.so.6 (0x00007f612ce7c000)
    libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f612cb45000)
    libXext.so.6 => /usr/lib/libXext.so.6 (0x00007f612c933000)
    libXt.so.6 => /usr/lib/libXt.so.6 (0x00007f612c6ce000)
    libXaw.so.7 => /usr/lib/libXaw.so.7 (0x00007f612c45e000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x00007f612c241000)
    libfreeimage.so.3 => /usr/lib/libfreeimage.so.3 (0x00007f612bd73000)
    libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f612bb55000)
    libXmu.so.6 => /usr/lib/libXmu.so.6 (0x00007f612b93c000)
    libXpm.so.4 => /usr/lib/libXpm.so.4 (0x00007f612b72b000)
    libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f612b527000)
    libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f612b321000)
    libdl.so.2 => /lib/libdl.so.2 (0x00007f612b11d000)
    libzzip-0.so.13 => /usr/lib/libzzip-0.so.13 (0x00007f612af15000)
    libz.so.1 => /lib/libz.so.1 (0x00007f612acfd000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f612a9f7000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f612a7e0000)
    libm.so.6 => /lib/libm.so.6 (0x00007f612a55d000)
    libc.so.6 => /lib/libc.so.6 (0x00007f612a1da000)
    libuuid.so.1 => /lib/libuuid.so.1 (0x00007f6129fd4000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f612dcfc000)

Resolution

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.

Useful links here and here

+2  A: 

It's rather simple.

The OS looks for libraries in the directories that exist in the ldconfig.

it seems that libOgreTerrain.so links against some other libraries that were not explicitly specified.

Try this first:

LD_LIBRARY_PATH=/home/esr/ogre/lib ./a.out

You can display dynamic linking paths like that:

ldd ./a.out
qdot
setting the LD_LIBRARY_PATH manually at least suppresses the error, I believe it fixes it. How do I correct this from the standpoint of compiler arguments?
EricR
That means you're having some library that is a dependency of libOgreTerrain.so. Use ldd to check which one. Then, link against it as well.
qdot
Linked against everything that libOgreTerrain links against and it's still returning the same error. Edited above.
EricR
Can you post what ldd a.out shows?
qdot
posted accordingly
EricR
You can hardcode the path to the libraries within the executable, add the flag `-Wl,-R,/home/esr/ogre/lib` to the linking.
nos
That's just about what I've done, I saw links to the -R option, and discovered that g++ doesn't accept -R as an option.
EricR
Edit to my previous comment, I added an addendum to the post under "Resolution"
EricR