MacOSX: which dynamic libraries linked by binary?

后端 未结 2 508
深忆病人
深忆病人 2021-02-18 18:28

I have not been able to figure out why my binary is not loading. It is a dylib loaded by MATLAB (MEX-file), and links to quite a few dylibs in different locations. MATLAB tells

2条回答
  •  北海茫月
    2021-02-18 19:26

    Rob Mayoff's answer is a great solution when working with executables. If you find you need to check the runtime dependencies of a dylib, the following script my-ldd may be useful.

    #!/usr/bin/env bash 
    
    while getopts "r" OPTION; do
      case $OPTION in   
        r) export DYLD_PRINT_RPATHS=1;;
      esac
    done
    shift $((OPTIND-1))
    
    cp `which true` .
    DYLD_PRINT_LIBRARIES=1 \
    DYLD_PRINT_LIBRARIES_POST_LAUNCH=1 \
    DYLD_INSERT_LIBRARIES=$1 \
    ./true
    rm ./true
    

    where a the script may be invoked as

    my-ldd ./foo.dylib
    

    or (with rpath attempts echo'd)

    my-ldd -r ./foo.dylib
    

提交回复
热议问题