Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix library load path of Math-O file
#!/bin/bash
# Fix library load path
# Author: @ohdarling88
# Thanks to http://stackoverflow.com/questions/4677044/how-to-use-dylib-in-mac-os-x-c#answer-11585225
BIN=$1
BINNAME=`basename $BIN`
DYLIBS=`otool -L $BIN | grep "/opt" | awk -F' ' '{ print $1 }'`
mkdir -p lib
for dylib in $DYLIBS; do
name=`basename $dylib`
if [ ! -f lib/$name ]; then
echo Copying $dylib ...
cp $dylib lib/
fi
done
for dylib in $DYLIBS; do
name=`basename $dylib`
if [ "$BINNAME" != "$name" ]; then
install_name_tool -change $dylib @executable_path/lib/$name $BIN
fi
done
otool -L $BIN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.