macで共有ライブラリの依存関係を調べる
mysql2 gem を mysql5.6 の libmysqlclient.a と static link したい話 を読んでいて、macでも共有ライブラリの依存関係調べようとしたら、
zsh: command not found: ldd
lddの代わりにotool
コマンドを使う。
% otool -L .rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.17/lib/mysql2/mysql2.bundle .rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.17/lib/mysql2/mysql2.bundle: /usr/local/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0) /usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 50.0.0) /usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 50.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
otoolのオプションはこんな感じ。
-l
とかも便利そう。
% otool Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool [-arch arch_type] [-fahlLDtdorSTMRIHGvVcXmqQjC] [-mcpu=arg] [--version] <object file> ... -f print the fat headers -a print the archive header -h print the mach header -l print the load commands -L print shared libraries used -D print shared library id name -t print the text section (disassemble with -v) -p <routine name> start dissassemble from routine name -s <segname> <sectname> print contents of section -d print the data section -o print the Objective-C segment -r print the relocation entries -S print the table of contents of a library -T print the table of contents of a dynamic shared library -M print the module table of a dynamic shared library -R print the reference table of a dynamic shared library -I print the indirect symbol table -H print the two-level hints table -G print the data in code table -v print verbosely (symbolically) when possible -V print disassembled operands symbolically -c print argument strings of a core file -X print no leading addresses or headers -m don't use archive(member) syntax -B force Thumb disassembly (ARM objects only) -q use llvm's disassembler (the default) -Q use otool(1)'s disassembler -mcpu=arg use `arg' as the cpu for disassembly -j print opcode bytes -C print linker optimization hints --version print the version of /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool