Error while loading shared libraries: Linux cross compilation

Written by Tom on Thursday 16/08/07

While attempting a cross compile I got this error from the target.

Error while loading shared libraries .....

problem was the location of the library.

On the development PC it is located at /usr/arm/lib/ on the target device it is located in /lib

To correct the error a change to the compiler options is required.

-Wl,-rpath /lib is added.

-Wl passes an option to the linker.

-rpath DIR Add a 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 locate shared objects at runtime.

If we browse the obj file via arm-linux-objdump -p "binaryfile" we see that the RPATH is now set correctly.