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

I would like to include and 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


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:

  QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN
  QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN/lib
  QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN/libs

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.

UNIX / Linux is going to look in LD_LIBRARY_PATH (if set) first before looking in the system standard libs. So if you set that, you can indeed override. Just like setting the PATH on Windows. Same effect. The ordering matters.

You can add ./ or . to LD_LIBRARY_PATH as well.


LD_LIBRARY_PATH and QMAKE_RPATH never worked for me. Instead, I set QMAKE_RPATHDIR in my .pro file. For example after having built and installed (make install) Qt, it has been placed in /usr/local/Trolltech/Qt-4.8.5/lib/. I then write the following in my .pro file:

QMAKE_RPATHDIR += /usr/local/Trolltech/Qt-4.8.5/lib/

Note 1: Relative paths seem not to work. Prefer absolute paths.

Note 2: When you then make, you can see that the following option is given to the linker: -Wl,-rpath,/usr/local/Trolltech/Qt-4.8.5/lib/

Note 3: To be sure that the binary links dynamically to the correct library, you can display the version of Qt at runtime delivered by qVersion().

Need Your Help

Invalid Signal processing library in Linux

c linux gcc signals

I'm trying to compile a signal processing program in Linux (Ubuntu 12.01 LTS). Here is my code: