Linking to a dynamic library on a Mac with full path

前端 未结 4 1570
生来不讨喜
生来不讨喜 2020-12-14 02:09

I am linking a (Python extension) library that embeds the Matlab engine with the following command (generated using cmake)

c++ -mmacosx-version-min=10.6 -bun         


        
相关标签:
4条回答
  • 2020-12-14 02:48

    You can also use symbolic link !

    0 讨论(0)
  • 2020-12-14 02:58

    Note that some of the problems with DYLD_LIBRARY_PATH can be prevented by using DYLD_FALLBACK_LIBRARY_PATH instead. This will only be used if the lib cannot be found in the default paths.

    0 讨论(0)
  • 2020-12-14 03:00

    Manually changing the files using install_name_tool

    install_name_tool -change "@loader_path/libeng.dylib" "/Applications/MATLAB_R2009b.app/bin/maci64/libeng.dylib" library.so 
    install_name_tool -change "@loader_path/libmx.dylib" "/Applications/MATLAB_R2009b.app/bin/maci64/libmx.dylib" library.so 
    

    I could use this as a temporary fix, but I wonder if there isn't a better solution where the linker is given a setting to use the full paths.

    0 讨论(0)
  • 2020-12-14 03:08

    Look into the -rpath option to the ld command to control this. You might also be interested in the contents of https://github.com/bimargulies/jni-origin-testbed, which is a demonstration of some relevant technology.

    The critical technique here is:

    install_name_tool -change libsl2.so "@loader_path/libsl2.so" libsl1.so
    
    0 讨论(0)
提交回复
热议问题