2

As an example the following will set RUNPATH

matthewh@ORAC:~/dev/test$ g++ test.cpp -ldl -Wl,-rpath,\$ORIGIN
matthewh@ORAC:~/dev/test$ objdump -x a.out | grep RUN
  RUNPATH              $ORIGIN

However, as a more complex example I'm trying to set this for a library that is compiled with a makefile generated with configure.

I run

export LDFLAGS=-Wl,-rpath,\$ORIGIN
./configure
make
objdump -x library.so | grep RUN
  RUNPATH              RIGIN

Obviously Make is expanding $O instead of putting a literal $O in the output.

How do I overcome this? I've tried escaping it but it's presenting strange output into runpath.

Ok, Specifically I'm attempting to compile ilmbase-2.2.1 from OpenEXR and set the RUNPATH. It's more complicated than a single Makefile as it's using recursive Make!

The top level Makefile ends up setting the variable LDFLAGS= I've tried manually editing that to be $$ORIGIN as suggested in other places but still, it comes through as -Wl,-rpath,RIGIN

Now I'm a bit stuck. Short of editing it after the path is set by rewriting it with some kind of ELF editor which is ugly.

hookenz
  • 36,432
  • 45
  • 177
  • 286
  • Also see [rpath=$ORIGIN not having desired effect?](https://stackoverflow.com/q/6324131/608639) and [A description of RPATH $ORIGIN LD_LIBRARY_PATH and portable linux binaries](https://enchildfone.wordpress.com/2010/03/23/a-description-of-rpath-origin-ld_library_path-and-portable-linux-binaries/). The second reference uses `XORIGIN/../lib`, and then uses `chrpath` to change to `$ORIGIN/../lib` to avoid the quoting problems. You may also want `-Wl,--enable-new-dtags`. – jww Oct 19 '18 at 02:39

1 Answers1

4

Oh wow. This seems to work.

./configure LDFLAGS='-Wl,-rpath,\$$ORIGIN'

The magic \$$ vs just $$

What's the backslash mean in gnu make then?

hookenz
  • 36,432
  • 45
  • 177
  • 286
  • It doesn't mean anything to Make but it will prevent the shell from expanding the `$` even when something discards the surrounding single-quotes. – Mike Kinghan Oct 18 '18 at 09:50