I would like to use the -rpath linker option to set the .so search path. I'd like it to search [app_path]/../lib
. I've tried add this to my qmake .pro
file:
QMAKE_LFLAGS += -Wl,-rpath=$ORIGIN/../lib/
But qmake links my project this way:
g++ -Wl,-rpath=RIGIN/../lib/ -Wl,-O1 -o myoutput main.o [...]
How can I escape the $ORIGIN
?
I found here a way to properly escape it:
QMAKE_LFLAGS += '-Wl,-rpath,\'\$$ORIGIN/../mylibs\''
If you want $ORIGIN
to be (properly) evaluated while building you can simply add this to your .pro
file:
QMAKE_RPATHDIR += $ORIGIN/../mylibs
This is a really old question, but for people getting here through a search: the methods described in the old answers are not needed anymore. Modern Qt versions (5.9 in my case), allow you to just use this:
QMAKE_RPATHDIR += lib
This will add the needed entries (including $ORIGIN
and -Wl,-z,origin
where needed) automatically to the makefile, as long as you're using a relative directory. Meaning that lib
will produce the needed "origin" entries, while something like /lib
will not. Any relative directory you add to QMAKE_RPATHDIR
will be made relative to $ORIGIN
automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With