Reputation: 1931
I know how to use nm to display the undefined symbols in a binary. I also know how to use otool to display which libraries the binary is linked to.
But I don't know how to display for each undefined symbol, which library the linker is expected to find them ?
Note: I am assuming that such information is stored in the mach-o binary, since I have seen before runtime error where dyld would tell you about a missing symbol and pointing out exactly which library it expected to find the symbol in.
Upvotes: 1
Views: 979
Reputation: 921
I wrote a shell script to do this:
#!/bin/bash
# Make sure a binary file is passed as an argument
if [ $# -ne 1 ]; then
echo "Usage: $0 <binary_file>"
exit 1
fi
binary_file=$1
# Find undefined symbols
undefined_symbols=$(nm -u $binary_file | awk '{print $2}')
# Iterate over undefined symbols
for symbol in $undefined_symbols; do
# Find the library that contains the symbol
library=$(otool -L $binary_file | grep $symbol | awk '{print $1}')
# Print the symbol and the library it belongs to
echo "$symbol is in $library"
done
Upvotes: 0