MacOSX: which dynamic libraries linked by binary?

后端 未结 2 516
深忆病人
深忆病人 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:21

    Try setting these environment variables before running matlab:

    export DYLD_PRINT_LIBRARIES=1
    export DYLD_PRINT_LIBRARIES_POST_LAUNCH=1
    export DYLD_PRINT_RPATHS=1
    

    Run man dyld for more possibilities.

    You can also set the variables for just the matlab command like this:

    DYLD_PRINT_LIBRARIES=1 DYLD_PRINT_LIBRARIES_POST_LAUNCH=1 DYLD_PRINT_RPATHS=1 matlab
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题