Skip to content

Instantly share code, notes, and snippets.

@ohdarling
Created December 6, 2012 15:58
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 ohdarling/4225568 to your computer and use it in GitHub Desktop.
Save ohdarling/4225568 to your computer and use it in GitHub Desktop.
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