Skip to content
This repository was archived by the owner on Nov 27, 2017. It is now read-only.
This repository was archived by the owner on Nov 27, 2017. It is now read-only.

Use patchelf to set RPATH #7

@sjackman

Description

@sjackman

Nicolas Hillegeer wrote...

Hey!

I just tried to post an issue to the issue tracker but it seems it won't budge, so I'll just paste my findings over to you:

NOTE: this issue might be double-posted, I think there was some issue with github so it didn't appear for me...

I really wanted ag, the silver searcher and I really wanted it through homebrew because I like pretty colours and upgrades, and dependency building, and rainbows.

I basically installed with

git clone git://github.com/Homebrew/linuxbrew.git
sudo mv linuxbrew /opt/homebrew
sudo chown `whoami`:`whoami` /opt/homebrew -R
edit [.zshrc/.bashrc/...] and add /opt/homebrew/bin in front of $PATH

So, that left me with three tiny hacks to get it to work:

  1. Setup more environment variables in .zshrc, which basically comes down to
export PATH="/opt/homebrew/bin:$PATH"                  # already done earlier
export HOMEBREW_PREFIX="/opt/homebrew"
export HOMEBREW_REPOSITORY="/opt/homebrew"
export HOMEBREW_CELAR="/opt/homebrew/Cellar"
export HOMEBREW_CACHE="/opt/homebrew/hbcache"
  1. to fix brew doctor, it seems to assume mktemp is in/usr/bin/mktemp, on debian it's in /bin/mktemp

Success!!! ag installs, drags in pcre kicking and screaming, and I am the proud father of a new compiled silver searcher.

But wait... it says that it can't find libpcre.so.1 when it runs. But I do have it, it got installed to /opt/homebrew/lib as part of the dependency resolving phase. What do we do?

  1. The first reflex would be to add /opt/homebrew/lib to LD_LIBRARY_PATH. Which would probably cause weird troubles for users down the road. There are some articles out there detailing the pitfalls of LD_LIBRARY_PATH. Especially on a linux system such as debian, I just wouldn't do it.

But, is there a way to change the LD_LIBRARY_PATH for just one executable? Well yea, we could write a wrapper script! There are a lot of packages that do that. And it's bad, but not quite as evil as changing LD_LIBRARY_PATH. So, I could hack homebrew to have it generate wrappers instead of symlinks.

But that's so dirty...

And I'm so lazy...

And I don't know ruby...

So I bust out google-fu and find that in fact, there is a solution that works for many unices. Basically, every executable has the possibility to have a RPATH and a RUNPATH. It's basically exactly what we want, the runtime linker will look first in RPATH, then in the normal path and last but not least in RUNPATH. At least that's my understanding.

But I find that you can set this variable at link-time, with a switch to ld or gcc. :(

That would mean hacking homebrew again.

I google once more before giving up and I find the venerable patchelf. Which... patches elfs to have a different RUNPATH. Exactly what we need.

cd /opt/homebrew/bin
patchelf --set-rpath '$ORIGIN/../lib' ag                   # $ORIGIN refers to the current directory, don't evaluate it, use the single quotes

Does it work? Why yes, it works. Now I can run homebrew on my debian wheezy. Nice.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions