Skip to content

Instantly share code, notes, and snippets.

@basnijholt
Created April 4, 2025 16:56
Show Gist options
  • Save basnijholt/811307f125619c53ef876f8ea6ab6685 to your computer and use it in GitHub Desktop.
Save basnijholt/811307f125619c53ef876f8ea6ab6685 to your computer and use it in GitHub Desktop.
#!/bin/bash
# filepath: fix_lib_paths.sh
# https://github.com/conda-forge/numpy-feedstock/issues/347#issuecomment-2746317575
# Activate the conda environment and run this script.
set -e
LIB_PATH="$CONDA_PREFIX/lib"
# Find all dylib files
find "$LIB_PATH" -name "*.dylib" -o -name "*.so" | while read -r library; do
echo "Processing $library..."
# Extract all LC_RPATH entries
rpaths=$(otool -l "$library" | grep -A2 LC_RPATH | grep "path " | awk '{print $2}')
# Create a temporary file to track seen rpaths
temp_file=$(mktemp)
# Check for duplicates and remove them
echo "$rpaths" | while read -r rpath; do
if [[ -z "$rpath" ]]; then
continue
fi
if grep -q "^$rpath$" "$temp_file"; then
echo " Removing duplicate RPATH: $rpath"
install_name_tool -delete_rpath "$rpath" "$library" || true
else
echo "$rpath" >> "$temp_file"
echo " Keeping RPATH: $rpath"
fi
done
# Re-sign the library
echo " Re-signing $library"
codesign --force --sign - "$library" || echo " Warning: Could not sign $library"
# Clean up the temporary file
rm -f "$temp_file"
echo "Done with $library"
echo "-----------------------"
done
echo "All libraries processed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment