unsafe use of relative rpath libboost.dylib when making boost.python helloword demo?

后端 未结 2 1741
轻奢々
轻奢々 2020-12-31 19:49

Recently, I am learning boost C++ library. I want to use python to call exist C++ project. I have install boost under OSX 10.11 using brew install boost. My pyt

相关标签:
2条回答
  • 2020-12-31 20:46

    Take this link as a reference.

    To my problem, use otool -L hello.so:

    hello.so:
        hello.so (compatibility version 0.0.0, current version 0.0.0)
        libboost_python.dylib (compatibility version 0.0.0, current version 0.0.0)
        /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
    

    you can see that libboost_python.dylib is not point to the really exist path.

    so use this command:

    install_name_tool -change libboost_python.dylib /usr/local/lib/libboost_python.dylib hello.so 
    

    and run otool -L hello.so again:

    hello.so:
        hello.so (compatibility version 0.0.0, current version 0.0.0)
        /usr/local/lib/libboost_python.dylib (compatibility version 0.0.0, current version 0.0.0)
        /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
    

    and finally run python test.py, I get the result.

    0 讨论(0)
  • 2020-12-31 20:47

    It is advisable to change the Boost dynamic libraries themselves on MacOS instead of changing the executables or other dynamic libraries linked against them. Run the bash script given below in the directory that contains your libboost_XXX.dylib libraries:

    #!/bin/bash
    
    # Modify the absolute dylib paths baked into the libraries
    for i in *.dylib
    do
        FULLPATH=`pwd`/$i
        install_name_tool -id $FULLPATH $i
        echo -change $i $FULLPATH
        done > changes
    for i in *.dylib
    do
        install_name_tool `cat changes` $i
    done
    rm changes
    

    You will need to do this only once after you built the Boost libraries. No mucking around with the executables linking against them is needed.

    0 讨论(0)
提交回复
热议问题