Created
December 3, 2012 01:11
-
-
Save mbohun/4191988 to your computer and use it in GitHub Desktop.
rpath, RPATH, readelf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Often you want to distributed/install alongside with your | |
| # executable-s some (of yours or some 3rd party) shared libraries. | |
| # In order for these shared libs to be found by the dynamic linker | |
| # one has to either: | |
| # - ask the user to manually set the LD_LIBRARY_PATH or | |
| # - add tge dir with the shared libs to /etc/ld.so.conf OR | |
| # /etc/ld.so.conf.d/ (sys wide and requires root/sudo) | |
| # - provide a wrapper shell startup script that sets LD_LIBRARY_PATH | |
| # or even preloads some shared libraries prior to running your | |
| # executable OR | |
| # - use the so called rpath to encode the shared lib directories path | |
| # into your executable, the encoded rpath can use both absolute | |
| # and relative path-s (this is handy if you wish to | |
| # distribute/install your sharedlibs into a location relative to | |
| # your executable), here is an example: | |
| # -Xlinker -R./some/path option makes gcc to pass the rpath option | |
| # onto the linker, and as shown in the example bellow you can pass | |
| # multiple of these | |
| # | |
| $ gcc test_rpath.c -Xlinker -R./plugins -Xlinker -R/opt/test/lib | |
| # you may use readelf to verify/examine (if and how) RPATH got encoded in your executable (or shared lib) | |
| # | |
| $ readelf -a a.out | grep -i rpath | |
| 0x0000000f (RPATH) Library rpath: [./plugins:/opt/test/lib] | |
| 38: 00000000 0 FILE LOCAL DEFAULT ABS test_rpath.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chrpath -l a.outalso lists rpath.