PDA

View Full Version : My 3rd party library RPATH problem (Linux)



jezze_h
8th September 2011, 10:03
Hi,

I'm developing a 3rd party library that can be installed as a part of Qt SDK.
I have the Qt SDK installed to the default dir - in my home dir, /home/username/QtSDK.

The problem is that when I compile the library, linker links absolute paths of my home dir to the binary.
When I check the lib dependencies of my library with ldd ./libmylib.so, there are:

libQtMobilitySimulator.so.1 => /home/username/QtSDK/Simulator/QtMobility/gcc/lib/libQtMobilitySimulator.so.1 (0x008a1000)
libQtServiceFramework.so.1 => /home/username/QtSDK/Simulator/QtMobility/gcc/lib/libQtServiceFramework.so.1 (0x009fc000)
libQtCore.so.4 => /home/username/QtSDK/Simulator/Qt/gcc/lib/libQtCore.so.4 (0x00254000)

Now, when I copy the lib to another computer with other user name, ldd cannot find the dependecies.

What is the preferred way on Linux platform to change those library paths in the binary to correspond the destination computer Qt paths?

On Mac OS X there's a tool called install_name_tool, which does the trick. Qt SDK installer seems changing RPATHs on the fly when it installs the libraries to desired location. For convenience, I'd like to have the library installed under the default path /home/username/QtSDK, not in the /usr/lib.

Many thanks in advance!

wysota
8th September 2011, 11:04
rpath is only a suggestion. If the linker can't find the library in directories specified by rpath, it will perform a regular lookup for the libraries. If it doesn't work for you then it means you didn't place your Qt libs in a directory the linker looks for libraries.

jezze_h
8th September 2011, 11:38
Thanks for the clarification!

Another question is:
Is there a way for replacing those linker absolute paths (e.g. /home/username/QtSDK/Simulator/QtMobility/gcc/lib/) with an empty ones?
I think that could be some option provided by ld linker? Would be nice if my home dir is not listed in the library binary when I release the lib :)

wysota
8th September 2011, 12:11
Is there a way for replacing those linker absolute paths (e.g. /home/username/QtSDK/Simulator/QtMobility/gcc/lib/) with an empty ones?
Not really. What you can do is not add any rpath entries at all. Clearing QMAKE_LIBDIRS (or something like that) should do the trick.