Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qmake and passing $ORIGIN to linker option -rpath

Tags:

qmake

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?

like image 782
Vitor Py Avatar asked Sep 21 '11 21:09

Vitor Py


3 Answers

I found here a way to properly escape it:

QMAKE_LFLAGS += '-Wl,-rpath,\'\$$ORIGIN/../mylibs\'' 
like image 181
Vitor Py Avatar answered Nov 09 '22 05:11

Vitor Py


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

QMAKE_RPATHDIR += $ORIGIN/../mylibs
like image 14
Aurelien Avatar answered Nov 09 '22 06:11

Aurelien


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.

like image 8
Nikos C. Avatar answered Nov 09 '22 04:11

Nikos C.