It doesn't work because you need yet a third layer of quoting: because you are passing this value to the configure
script via the command line you need to quote the value for the shell.
You run this:
./configure "LDFLAGS=-Wl,-rpath,\$\$ORIGIN/../lib"
The shell removes the first level of quoting before invoking configure
, so the value of LDFLAGS
that is put into your makefile is this:
LDFLAGS=-Wl,-rpath,$$ORIGIN/../lib
Then when make runs the linker, it will convert the escaped $$
into a single $
, and make will invoke a shell and pass your link line with the option:
-Wl,-rpath,$ORIGIN/../lib
The shell will expand $ORIGIN
because it looks like a shell variable, expand it to the empty string, and you get the result -Wl,-rpath,/../lib
.
To get the quoting right it's often useful to work backwards. When make invokes your link line it needs to escape the $ORIGIN
so the shell doesn't expand it, so you want the argument to be something like:
'-Wl,-rpath,$ORIGIN/../lib'
In order to get that, you need your LDFLAGS
to be set to something like:
LDFLAGS='-Wl,-rpath,$$ORIGIN/../lib'
In order to get that, you need to escape it all from the shell when you invoke configure, including the single-quotes, something like:
./configure "LDFLAGS='-Wl,-rpath,\$\$ORIGIN/../lib'"
(note, I didn't try this)