Skip to content

Instantly share code, notes, and snippets.

@seongyooncho
Last active November 10, 2025 01:50
Show Gist options
  • Select an option

  • Save seongyooncho/4191f3fc0b39c2741a9c47052fd11478 to your computer and use it in GitHub Desktop.

Select an option

Save seongyooncho/4191f3fc0b39c2741a9c47052fd11478 to your computer and use it in GitHub Desktop.
opencv411
# --- A) core 탭 준비 (extract가 히스토리를 필요로 함)
export HOMEBREW_NO_INSTALL_FROM_API=1
brew tap homebrew/core || true
git -C "$(brew --repo homebrew/core)" fetch --unshallow --tags 2>/dev/null || \
git -C "$(brew --repo homebrew/core)" fetch --tags
# --- B) 내 로컬 탭 만들기
brew tap-new $USER/local-tap
# --- C) opencv 4.11 추출(4.11.1 우선, 안되면 4.11.0) 및 설치
brew extract --version=4.11.1 opencv $USER/local-tap || \
brew extract --version=4.11.0 opencv $USER/local-tap
brew install $USER/local-tap/[email protected] || \
brew install $USER/local-tap/[email protected]
# --- D) MotionScore가 버전 경로를 보도록 실행 파일만 패치 (@rpath도 추가)
APP="/Users/motionary/MotionScore/MotionScore"
OCV_OPT="$(ls -d /opt/homebrew/opt/[email protected].* | head -1)"
chmod u+w "$APP" 2>/dev/null || true
# rpath 추가(설치된 4.11 lib 폴더를 검색)
install_name_tool -add_rpath "$OCV_OPT/lib" "$APP" 2>/dev/null || true
# 실행파일 안의 "/opt/homebrew/opt/opencv/lib/libopencv_*.411.dylib" 의존성을
# 설치된 버전 경로로 일괄 교체
for lib in "$OCV_OPT"/lib/libopencv_*.411.dylib; do
base="$(basename "$lib")"
install_name_tool -change "/opt/homebrew/opt/opencv/lib/$base" "$lib" "$APP" || true
done
# (서명 필요할 수 있어 ad-hoc 서명)
codesign --force --sign - "$APP" 2>/dev/null || true
# --- E) 확인 및 실행
otool -L "$APP" | grep opencv
"$APP"
APP="/Users/motionary/MotionScore/MotionScore"
OCV_CELLAR="$(brew --cellar opencv)"
OCV_VER="$(ls -1 "$OCV_CELLAR" | tail -1)"
LIBDIR="$OCV_CELLAR/$OCV_VER/lib"
# 실행파일에 4.12 라이브러리 경로(rpath) 추가
chmod u+w "$APP" 2>/dev/null || true
install_name_tool -add_rpath "$LIBDIR" "$APP" 2>/dev/null || true
# 실행파일이 참조하는 *.411.dylib들을 4.12로 일괄 교체
otool -L "$APP" | awk '/libopencv_.*\.411\.dylib/{print $1}' | while read -r OLD; do
NEW="$LIBDIR/$(basename "$OLD" | sed 's/\.411\./.412./')"
if [ -e "$NEW" ]; then
install_name_tool -change "$OLD" "$NEW" "$APP"
else
# .4.12.0 형태가 있을 때 대안
BASE=$(basename "$OLD" | sed 's/\.411\.dylib$//')
CAND=$(ls "$LIBDIR/$BASE".4*.dylib 2>/dev/null | head -1)
[ -n "$CAND" ] && install_name_tool -change "$OLD" "$CAND" "$APP"
fi
done
# 서명 문제 방지(임시 ad-hoc 서명)
codesign --force --sign - "$APP" 2>/dev/null || true
# 실행
"$APP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment