Droopycom
Droopycom

Reputation: 1931

For an OS X executable, how to display which library an undefined symbol is expected in?

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

Answers (2)

Bryan Potts
Bryan Potts

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

Ken Thomases
Ken Thomases

Reputation: 90671

Are you just missing the use of the -m flag to nm?

Upvotes: 1

Related Questions