Linux runtime linker error

I am working on the tutorial First Steps on the Project POCO site and I have successfully created a library (Debian Linux, 2.6.26, gcc 4.3.2) in my home directory

~ / Development / POCO

with shared libraries located in

~ / Development / POCO / lib / Linux / x86_64 / lib

My problem is that any application I create that depends on these libraries can only run from the shared library directory.

~ / Development / POCO / lib / Linux / x86_64 $ ldd ~ / Development / Cloud / DateTimeSample / bin / Linux / x86_64 / DateTime
        linux-vdso.so.1 => (0x00007fffe69fe000)
        libPocoFoundation.so.6 (0x00007fa8de44f000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x00007fa8de233000)
        libdl.so.2 => /lib/libdl.so.2 (0x00007fa8de02f000)
        librt.so.1 => /lib/librt.so.1 (0x00007fa8dde26000)
        libstdc ++. so.6 => /usr/lib/libstdc++.so.6 (0x00007fa8ddb1a000)
        libm.so.6 => /lib/libm.so.6 (0x00007fa8dd897000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fa8dd680000)
        libc.so.6 => /lib/libc.so.6 (0x00007fa8dd32d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa8de7e0000)

And launching DateTime from that directory will work as you expected. However

~ / Development / Cloud / DateTimeSample / bin / Linux / x86_64 $ ldd DateTime
        linux-vdso.so.1 => (0x00007fff24dfe000)
        libPocoFoundation.so.6 => not found
        libpthread.so.0 => /lib/libpthread.so.0 (0x00007ffc1c7dd000)
        libdl.so.2 => /lib/libdl.so.2 (0x00007ffc1c5d9000)
        librt.so.1 => /lib/librt.so.1 (0x00007ffc1c3d0000)
        libstdc ++. so.6 => /usr/lib/libstdc++.so.6 (0x00007ffc1c0c4000)
        libm.so.6 => /lib/libm.so.6 (0x00007ffc1be41000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007ffc1bc2a000)
        libc.so.6 => /lib/libc.so.6 (0x00007ffc1b8d7000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ffc1c9f9000)

so running the executable from any other directory results in

error while loading shared libraries: libPocoFoundation.so.6: cannot open shared object file: No such file or directory

Looking at the output of the make process, the directory is correct

g ++ [blah] -L / home / npalko / Development / POCO / lib / Linux / x86_64 
           -lPocoFoundation

I have tried installing

LD_LIBRARY_PATH
      

on the
/ home / npalko / Development / POCO / lib / Linux / x86_64
but didn't change anything. Any help would be greatly appreciated!
+2


source to share


3 answers


If you don't want to deal with a variable LD_LIBRARY_PATH

, you can add the linker option -rpath

to the gcc command line. In your case, it would be:

gcc ... -Wl,-rpath=/home/npalko/Development/POCO/lib/Linux/x86_64

      



This effectively hardcodes this path into the executable, so it may or may not be suitable for your purposes.

+7


source


It fails?

LD_LIBRARY_PATH=/home/npalko/Development/POCO/lib/Linux/x86_64 ~/Development/Cloud/DateTimeSample/bin/Linux/x86_64/DateTime

      

Just thought you can't set LD_LIBRARY_PATH correctly



And this?

ls -alh /home/npalko/Development/POCO/lib/Linux/x86_64/libPocoFoundation.so

      

If both fail, I see no reason.

+2


source


You must tell the linker the path to your library

g++ [blah] -Wl,-rpath=/home/npalko/Development/POCO/lib/Linux/x86_64

      

-Wl means you are passing the option to the linker

-rpath is a linker option

Add the directory to the runtime library search path. This is used when linking an ELF executable with shared objects. All -rpath arguments are concatenated and passed to the runtime linker, which uses them to find shared objects at runtime. The -rpath parameter is also used when searching for shared objects, which are required for shared objects that are explicitly referenced;

+1


source







All Articles