6

I've just stumbled on some weird behavior: before I launch my application I've set the LD_LIBRARY_PATH to some local lib directory which contains all needed libs. After launch I have part(the most part) libs are loaded from the LD_LIBRARY_PATH but a few are loaded from the standard /usr/lib(e.g /usr/lib/libQtNetwork.so.4, /usr/lib/libSM.so.6). All those libs are contained in the directory which is listed in the LD_LIBRARY_PATH. Could anyone explain why do I have such behavior? I'm not very familiar with a Linux world but this article says that my approach should work

P.S. If I rename /usr/libs to something other I'll have my application running with all libs used from my libs location

Thank in advance!

Matthew Slattery
  • 45,290
  • 8
  • 103
  • 119
ixSci
  • 13,100
  • 5
  • 45
  • 79

2 Answers2

4

I've found the answer and the answer is RPATH. All Qt libraries are built with RPATH=$QT_INSTALL_DIR so the RPATH should be removed if you want to create "bundle" in Linux. RPATH can be removed by invoking chrpath command. Thanks all for help!

ixSci
  • 13,100
  • 5
  • 45
  • 79
  • I never understood the reasoning behind RPATH. It always seems to get in the way. – dietbuddha Mar 21 '11 at 14:39
  • 1
    @dietbuddha: The application should be told at compile time where to search for its shared libraries; it shouldn't have to rely on an environment variable. Often times, whoever is compiling is more skilled than whoever is running the program and therefore knows better. This is especially true on machines where many users log in and there is a dedicated team taking care of it. But I understand that as an administrator and user of a small semi-personal machine the feeling can be different – Davide Feb 22 '13 at 18:17
  • Thanks for answering your own question. You've helped me quite a lot. – Ruslan Nov 05 '13 at 11:51
1

Ok, seems you are using Qt, but the same principles applies and is not Qt specific.

The first thing to look at is your PATH environment variable, then QTDIR, then LD_LIBRARY_PATH.

Normally you do not need to "play" with LD_LIBRARY_PATH. If your PATH is correct then you should be fine.

As a side note (you probably know): To see the libraries used you can use the the ldd command. For example:

user@host:~/$ ldd $QTDIR/bin/qmake 
linux-vdso.so.1 =>  (0x00007fff169ff000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fb6bf63e000)
libm.so.6 => /lib/libm.so.6 (0x00007fb6bf3bb000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fb6bf1a3000)
libc.so.6 => /lib/libc.so.6 (0x00007fb6bee20000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb6bf97e000)

Assuming your QTDIR env variable is set. If you have QT if the linux distribution installed qmake will be in the path. If you did a custom install or compile you would need to set your path.

Good luck.

Derick Schoonbee
  • 2,971
  • 1
  • 23
  • 39
  • Derick, I need to play with LD_LIBRARY_PATH because I need standalone "bundle" which doesn't depend on the underlying system(like VMWare Linux installer). So the question is: why the LD_LIBRARY_PATH doesn't work like it should. Do LD_LIBRARY_PATH has the highest precedence or some other variable has higher one? – ixSci Mar 20 '11 at 15:31
  • Ok, SO might not be the right place as Yasir suggested. (PS: Also have a look here http://doc.qt.nokia.com/latest/deployment-x11.html.) Back to the point: LD_LIBRARY_PATH should have precedence but it's considered a hack. setuid or setgid can change behavior. See [here](http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/dlls.html). Are you sure your application has access to this variable? How do you launch your app? What is the output of ldd and `strace -o trace.txt ./ourprogram` ? – Derick Schoonbee Mar 20 '11 at 16:52
  • I've uploaded launch script and all output here: http://www.sendspace.com/file/pugplz – ixSci Mar 21 '11 at 08:33