Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set where a Qt app finds a Qt module?

I would like to include libQtGui.so.4 libQtNetwork.so.4 and libQtCore.so.4 in the same directory as where my app resides. How would I make Qt understand this? y purpose is to have a standalone app that uses shared libraries

like image 352
yan bellavance Avatar asked Mar 23 '10 02:03

yan bellavance


1 Answers

Setting the LD_LIBRARY_PATH environment variable is one option. For example:

export LD_LIBRARY_PATH=/path/to/dir/with/libs:$LD_LIBRARY_PATH

Another option is to set the RPATH of your Qt application during linking. Setting the RPATH to the value "$ORIGIN" will cause the dynamic linker to look in the same directory as your Qt application at runtime. For example, if using qmake, add the following snippet to your project file:

unix:!mac{
  QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN
  QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN/lib
  QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN/libs
  QMAKE_RPATH=
}

This will set the RPATH to "$ORIGIN:$ORIGIN/lib:$ORIGIN/libs", meaning that the dynamic linker will first look in the location of your Qt application, then in a lib subdirectory at its location, then in a libs subdirectory at its location, and finally in any system defined locations.

like image 69
baysmith Avatar answered Oct 29 '22 10:10

baysmith