18

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?

Vitor Py
  • 5,145
  • 4
  • 39
  • 62

4 Answers4

22

I found here a way to properly escape it:

QMAKE_LFLAGS += '-Wl,-rpath,\'\$$ORIGIN/../mylibs\'' 
Vitor Py
  • 5,145
  • 4
  • 39
  • 62
  • 4
    I just thought I'd mention that I had to add `-z origin` to get things working for me. So all together, that's `QMAKE_LFLAGS += '-Wl,-rpath,\'\$$ORIGIN/../lib\',-z,origin'`. – Parker Coates Nov 13 '13 at 20:17
  • This is the correct answer. I could not get QMAKE_RPATHDIR to work, and there is chatter on the 'net indicating that indeed QMAKE_RPATHDIR does not work. – John McGehee Jul 27 '16 at 17:43
15

If you want $ORIGIN to be (properly) evaluated while building you can simply add this to your .pro file:

QMAKE_RPATHDIR += $ORIGIN/../mylibs
Aurélien
  • 1,742
  • 1
  • 19
  • 30
  • Interesting. Is this a new option? – Vitor Py Jan 04 '13 at 18:57
  • 2
    I discovered it here while I was trying to make `QMAKE_RPATH` work: [QTBUG-8110](https://bugreports.qt-project.org/browse/QTBUG-8110). According to this link `QMAKE_RPATH` and `QMAKE_LFLAGS_RPATH` don't work anymore. `QMAKE_RPATHDIR` works for me at least with Qt 4.8.4 and Qt 4.8.5. – Aurélien Jan 05 '13 at 08:31
  • It is defined here: [qmake Variable Reference](http://doc.qt.digia.com/qt/qmake-variable-reference.html#qmake-rpathdir) – Aurélien Jan 05 '13 at 08:37
  • 4
    I've tried it in Qt 5.3-5.5 and it's doesn't work correctly. – αλεχολυτ Jul 10 '15 at 11:53
  • doesn't work on qt 5.5. Parker's "QMAKE_LFLAGS += .." answer is correct – vrogach May 25 '16 at 17:51
  • @VitorPy, my answer to your question is obviously outdated and your own answer is the most upvoted one. Please go ahead and make your answer the accepted one :) – Aurélien May 26 '16 at 14:32
  • 1
    @Aurelien My own answer is from 5 years ago, I have no idea if it still works.. I'm unsure of what to do. – Vitor Py May 31 '16 at 00:11
9

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.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
1

DOLLAR=$

QMAKE_LFLAGS += -Wl,-rpath=$${DOLLAR}$${DOLLAR}ORIGIN/../myLibs