最近,我在学习Boost C++库。我想用Python调用存在C++项目。我用brew install boost
在osx10.11下安装了boost。我的python版本2.7。在
我打个招呼。c:
char const* greet()
{
return "hello, world";
}
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(hello)
{
using namespace boost::python;
def("greet", greet);
}
和Makefile:
^{pr2}$但是,在我运行make
并得到你好。所以. 运行python代码时遇到以下错误:
import hello
print hello.greet()
错误:
Traceback (most recent call last):
File "test.py", line 4, in <module>
import hello
ImportError: dlopen(/Users/einverne/boost_test/hello.so, 2): Library not loaded: libboost_python.dylib
Referenced from: /Users/einverne/boost_test/hello.so
Reason: unsafe use of relative rpath libboost_python.dylib in /Users/einverne/boost_test/hello.so with restricted binary
以这个link作为参考。在
对于我的问题,请使用
otool -L hello.so
:你可以看到libboost_python.dylib不是指向真正存在的路径。在
所以使用以下命令:
^{pr2}$然后再次运行
otool -L hello.so
:最后运行
python test.py
,得到结果。在在MacOS上,建议更改Boost动态库本身,而不是更改链接到它们的可执行文件或其他动态库。在包含
libboost_XXX.dylib
库的目录中运行下面给出的bash
脚本:在构建Boost库之后,只需要执行一次。不需要在链接到它们的可执行文件上胡闹。在
相关问题 更多 >
编程相关推荐