Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux runtime linker error

I'm working though the First Steps tutorial on the POCO Project site, and I've successfully built the library (Debian Linux, 2.6.26, gcc 4.3.2) under my home directory

~/Development/POCO

with the shared libraries located in

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

My problem is that any application I build that depends on these libraries can only be 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 running DateTime from this directory would work as you would expect. 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 from the make process, the directory is correctly specified

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

I've tried setting

LD_LIBRARY_PATH
to
/home/npalko/Development/POCO/lib/Linux/x86_64
, but it has not changed anything. Any help would be greatly appreciated!
like image 225
Nicholas Palko Avatar asked Dec 07 '25 08:12

Nicholas Palko


1 Answers

If you don't want to have to deal with the LD_LIBRARY_PATH variable, you can add the linker -rpath option to the gcc command line. In your case, this would be:

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

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

like image 86
nall Avatar answered Dec 09 '25 22:12

nall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!