Reputation: 10546
I am trying to set the rpath in my spec file with a statement like
export LDFLAGS="-Wl-rpath=$ORIGIN/../lib"
But I can't correctly escape "$ORIGIN". I need the command to gcc to contain the string "$ORIGIN", not expand it anywhere along the line. I tried
\\\$ORIGIN
$$ORIGIN
\$\$ORIGIN
\\$\\$ORIGIN
\\\\\\$ORIGIN
\\\\\\\\$ORIGIN
and a few others with no success. What's the right sequence of escape characters?
Upvotes: 5
Views: 2832
Reputation: 4511
I managed to figure this one out. I used curl-7.19.7 for testing. From the command line, the following was sufficient to get make to pass $ORIGIN
through to the compiler:
export LDFLAGS='-Wl,-rpath=\$$ORIGIN/../lib'
./configure --prefix=/tmp/curl
make
make install
and I verified using readelf --dynamic /tmp/curl/bin/curl
.
However, from a specfile, I needed to escape the backslash an extra time. Here is what worked from the %build
section of the specfile for me:
%define ldflags LDFLAGS='-Wl,-rpath=\\$$ORIGIN/../lib'
%configure --enable-shared %{ldflags}
make %{?_smp_mflags}
To verify, here is the output from readelf
:
[faceplant ~/rpmbuild/specs]% readelf --dynamic ../buildroot/sis-curl-7.19.7-2.el6.x86_64/usr/local/curl-7.19.7/bin/curl
Dynamic section at offset 0x1c028 contains 26 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libcurl.so.4]
0x0000000000000001 (NEEDED) Shared library: [libssl.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libcrypto.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
0x0000000000000001 (NEEDED) Shared library: [libz.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000f (RPATH) Library rpath: [$ORIGIN/../lib:/usr/local/curl-7.19.7/lib]
0x000000000000000c (INIT) 0x401b98
0x000000000000000d (FINI) 0x40b2f8
0x000000006ffffef5 (GNU_HASH) 0x400260
0x0000000000000005 (STRTAB) 0x400cb0
0x0000000000000006 (SYMTAB) 0x4002c0
0x000000000000000a (STRSZ) 1229 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000015 (DEBUG) 0x0
0x0000000000000003 (PLTGOT) 0x61c220
0x0000000000000002 (PLTRELSZ) 2160 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x401328
0x0000000000000007 (RELA) 0x4012c8
0x0000000000000008 (RELASZ) 96 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffffe (VERNEED) 0x401258
0x000000006fffffff (VERNEEDNUM) 2
0x000000006ffffff0 (VERSYM) 0x40117e
0x0000000000000000 (NULL) 0x0
As you can see, $ORIGIN/../lib
made it into the RPATH field unscathed.
Hopefully this works for you.
(P.S. please ignore the /usr/local/<package>-<version>
prefixes. This is just a packaging method I've been experimenting with in order to meet some packaging needs for my organization.)
Upvotes: 2
Reputation: 80921
Alright. I did some quick testing and I believe I figured out what you need to do.
Try using one of the following:
export LDFLAGS="-Wl,-rpath=\\$\$ORIGIN/../lib"
or
export LDFLAGS="-Wl,-rpath="'\$$ORIGIN'"/../lib"
Upvotes: 2