views:

411

answers:

2

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

+1  A: 

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
mrjoltcola
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?
yan bellavance
+2  A: 

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.

baysmith
doesn't seem to be working.
yan bellavance
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'"
yan bellavance
removed those manually in the Makefile directly , pressed build all again then it passed...now to try it out.
yan bellavance
Does this example work?http://rapidshare.com/files/367247308/rpathExample.tar.gz.html
baysmith
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.
yan bellavance