我正在尝试为Boost.Python设置和编译Hello World示例:http://www.boost.org/doc/libs/1_57_0/libs/python/doc/tutorial/doc/html/python/hello.html
我在Homebrew中安装了bjam,boost,boost-build和boost-python:
brew install bjam
brew install boost
brew install boost-build
brew install boost-python
我的python安装也是通过Homebrew。我不确定如何正确修改示例Jamroot
文件,以便它与我的系统设置兼容。我将提升路径更改为: /usr/local/Cellar/boost;
,但我不确定需要更改的其他路径。当前设置给出了以下错误:
> bjam
notice: no Python configured in user-config.jam
notice: will use default configuration
Jamroot:26: in modules.load
*** argument error
* rule use-project ( id : where )
* called with: ( boost : /usr/local/Cellar/boost; project : requirements <library>/boost/python//boost_python <implicit-dependency>/boost//headers : usage-requirements <implicit-dependency>/boost//headers )
* extra argument project
/usr/local/share/boost-build/build/project.jam:1138:see definition of rule 'use-project' being called
/usr/local/share/boost-build/build/project.jam:311: in load-jamfile
/usr/local/share/boost-build/build/project.jam:64: in load
/usr/local/share/boost-build/build/project.jam:145: in project.find
/usr/local/share/boost-build/build-system.jam:535: in load
/usr/local/share/boost-build/kernel/modules.jam:289: in import
/usr/local/share/boost-build/kernel/bootstrap.jam:139: in boost-build
/usr/local/share/boost-build/boost-build.jam:8: in module scope
答案 0 :(得分:0)
BJAM
这是浪费你的时间 - 我假设你对BJAM
的兴趣是让你的代码真正有效的副产品hello_world
示例using namespace boost::python
我和你有完全相同的设置。我花了年龄让这个工作,因为文档真的很阴暗(如你所知),在你知道它之前,你去了一些奇怪的兔子洞试图破解make文件和BJAM
安装。
您可以像使用setup.py
代码一样使用C
,如下所示......
您可以通过homebrew
通过以下命令获取正确的boost-python:
brew install boost --with-python --build-from-source
我认为brew install boost应该可以工作,但它是一个很大的安装,生命很短,可以做两次
#include <boost/python.hpp>
char const* greet()
{
return "Greetings!";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
然后您可以将setup.py
文件写为
from distutils.core import setup
from distutils.extension import Extension
hello_ext = Extension(
'hello_ext',
sources=['hello_ext.cpp'],
libraries=['boost_python-mt'],
)
setup(
name='hello-world',
version='0.1',
ext_modules=[hello_ext])
以下示例可用于:
python setup.py build_ext --inplace
将创建以下构建/目录和文件:
build/
hello_ext.so
这可以直接由python调用:
In [1]: import hello_ext
In [2]: hello_ext.greet()
Out[2]: 'Greetings!'