How can I set where a Qt app finds a Qt module?
Asked Answered
S

3

11

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

Stevenage answered 23/3, 2010 at 2:28 Comment(3)
you can also decide to link statically against the Qt libraries, that way you won't depend on the local Qt version installed (this is how Opera used to do it under linux)Congress
Problem with linking statically on the platform I am deploying on is that fontconfig is bugged (red Hat 5.3 uses fontconfig 2.4.1)Stevenage
when I try to build statically there is an undefined reference to FcTypeFreeQueryFace and when I try to update fontconfig it tells me that fontconfig is up to date.....bummer..then I have to find a way to modify the Qt files to build with a version of fontconfig that I provide. I am able to build my app dynamically with a fontconfig I provide but not staticallyStevenage
L
9

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.

Larena answered 23/3, 2010 at 4:35 Comment(5)
Here is the compile output: "g++:unrecognized option '-wl,--rpath=$ORIGIN'" "g++:unrecognized option '-wl,--rpath=$ORIGIN/lib'" "g++:unrecognized option '-wl,--rpath=$ORIGIN/libs'"Stevenage
removed those manually in the Makefile directly , pressed build all again then it passed...now to try it out.Stevenage
Does this example work? rapidshare.com/files/367247308/rpathExample.tar.gz.htmlLarena
actually it works now, there seemed to be a small typo, I changed it to QMAKE_LFLAGS += -Wl,-rpath=\\\$\$ORIGIN . Notice that it is actually an upper case W (for -Wl) and a single dash for -rpath. I also added LIBS+= libQtblabla.... but im going to check if it works without LIBS+=(LIBS+= by itself doesnt work for sure). Thanks alot that thing doesnt seem to be documented anywhere. P.S. I noticed the typo by looking at the Makefile and noticed the -Wl,-rpath being used elsewhere so I concluded there was a typoe. thanks again.Stevenage
That didn't worked for me. Could you suggest anything?Audacious
F
0

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.

export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
Farmhand answered 23/3, 2010 at 2:33 Comment(1)
I tried that and it doesnt work. I went into project and changed LD_LIBRARY_PATH to . but nothing changed when I went back to terminal and typed ldd ./MyApp ...I am building from the GUI...should I try from the command line?Stevenage
T
0

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().

Translunar answered 4/1, 2013 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.