Skip to content

Instantly share code, notes, and snippets.

Last active January 6, 2020 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MitchRatquest/5c4b0ea2c2936e9f9c88fba2400c76b4 to your computer and use it in GitHub Desktop.
Save MitchRatquest/5c4b0ea2c2936e9f9c88fba2400c76b4 to your computer and use it in GitHub Desktop.
Change shared library path on a binary
if [[ $UID != 0 ]]
echo "please run as root"
exit 1
mkdir -p $SHLIB_DEST
cp `which $BINARY` .
cp $(ldd -v $BINARY | grep "=>" | awk -F"=>" '{print $2}' | awk '{print $1}' | sort | uniq) $SHLIB_DEST/
cp $(which $BINARY) $SHLIB_DEST/
patchelf --set-rpath . $BINARY
#for any subsequent shlib you need to link to here too
if [ -f ]
patchelf --set-rpath . #handles in nano's case
INTERPRETER=$(basename $(ldd -v $BINARY | grep "=>" | grep ld | awk '{print $1'} | uniq | head -n1) )
sudo patchelf --set-interpreter /usr/lib/$BINARY/$INTERPRETER $BINARY
#now we need to create the binary wrapper to load all this correctly
cd ../..
mkdir -p bin
cd bin
cat << EOF >> $BINARY
export LD_LIBRARY_PATH=/usr/lib/$BINARY
/usr/lib/$BINARY/$BINARY "\$@"
chmod 777 $BINARY
cd ../..
tar -cvf $BINARY.tar usr/
echo "ta da!"
echo "extract with: tar xvf $BINARY.tar on the top level"
Copy link

MitchRatquest commented Feb 20, 2019

This is enough to get orca copied over. Once you rsync that tar, extract it, then you have to run these:

export LD_LIBRARY_PATH=/lib:/usr/local/lib/orca
modprobe snd_seq
orca --portmidi-list-devices
#you should see something like:
#ID: 0 Name: f_midi
orca --portmidi-output-device 0 midi

#in another terminal:
#these settings worked for me:
#OSS-midi -> input devices -> /dev/midi3
#I also have midi USB OTG configured

#I had accidentally typed pd in a terminal on my dekstop, and f_midi is the USB OTG midi, so it was working from 1 computer to another
#To make it work as intended (localhost) you need snd_card_virmidi enabled under audio in the kernel config
#I'm rebuilding a kernel to test this

#If you set LD_PRELOAD to the path of a shared object, that file will be loaded before any other library (including the C runtime,
LD_PRELOAD=/path/to/my/ /bin/ls
#update feb26: if you use LD_PRELOAD, you need to unset it after you run the command or you risk segfaulting
export LD_PRELOAD=

Copy link

mkdir -p nicegoodlibs
for BINARY in $@
rsync -avPL --relative $(ldd -v $BINARY | grep "=>" | awk -F"=>" '{print $2}' | awk '{print $1}' | sort | uniq) nicegoodlibs/
rsync -avPl --relative $BINARY nicegoodlibs
tar -cvf nicegoodlibs.tar nicegoodlibs
#if you don't want to mangle each binary, but copy over their depends wholesale
#might be good if doing an incremental version bump without a package manager, ie ipk or deb or whatever

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment